+ Start a Discussion
SaaspertSaaspert 

Salesforce to Salesforce (S2S) - How to recreate lookup relationship in the target org.

I am establishing S2S between two orgs . Org A (source Org) and Org B (Target Org)

 

Org A has an object (Object1) with look up on the two other objects (Object2 and Object3)

 

Object2 and Object3 are already externally shared with Org B.

 

while sharing Object1 , I am setting parentrecordid to Object2 so Object1 shows up correctly linked to Object2

 

but I am not able link Object1 with both Object2 and Object3 at the same time.

 

here is the code from the after insert trigger on Object1 in Org A.

 

stripped down code...

 

 

            PartnerNetworkRecordConnection newConnection = new PartnerNetworkRecordConnection (
            ConnectionId = networkId,
            LocalRecordId = obj1.Id, 
            ParentRecordId = obj1.obj2);

 

            insert  newConnection;

 

Thanks for your help.

Best Answer chosen by Admin (Salesforce Developers) 
adi kurugantiadi kuruganti

what you need to do is have a before insert trigger on the target org and relate the 2nd lookup field. Here are the steps

 

1) Share the 2nd lookup ID using a custom formula and map it to a text field on the target org

2) On insert in the target org, use the 2nd lookup ID to search for the connected 'local record id' by querying the PartnerNetworkRecordConnection table

 

Example:

List<PartnerNetworkRecordConnection> contactvalue = new List<PartnerNetworkRecordConnection>([select Id, ConnectionId, PartnerRecordId, LocalRecordId from PartnerNetworkRecordConnection where PartnerRecordId in :contactLst AND (Status ='Sent' OR Status = 'Received')]);

- here I'm using a list of contact ids from the source org which was passed using a custom formula field mapped to a text field on the target org and retrieving the local connected contact id 

 

 

3) Once you have the local record id set it to the appropriate field on Object 1 (the 2nd lookup field)

4) Do the above in before insert - much simpler

 

If you have specific questions email: s2s@salesforce.com

All Answers

adi kurugantiadi kuruganti

what you need to do is have a before insert trigger on the target org and relate the 2nd lookup field. Here are the steps

 

1) Share the 2nd lookup ID using a custom formula and map it to a text field on the target org

2) On insert in the target org, use the 2nd lookup ID to search for the connected 'local record id' by querying the PartnerNetworkRecordConnection table

 

Example:

List<PartnerNetworkRecordConnection> contactvalue = new List<PartnerNetworkRecordConnection>([select Id, ConnectionId, PartnerRecordId, LocalRecordId from PartnerNetworkRecordConnection where PartnerRecordId in :contactLst AND (Status ='Sent' OR Status = 'Received')]);

- here I'm using a list of contact ids from the source org which was passed using a custom formula field mapped to a text field on the target org and retrieving the local connected contact id 

 

 

3) Once you have the local record id set it to the appropriate field on Object 1 (the 2nd lookup field)

4) Do the above in before insert - much simpler

 

If you have specific questions email: s2s@salesforce.com

This was selected as the best answer
SaaspertSaaspert
worked like a charm - thanks
manjirimanjiri
i have established lookup relationship same way explained here. And it is working fine when i am manually creating objs obj1, obj2 and obj3 in my org1, it is getting created in org2. But in my application there is need for criteria based sharing. So i have written trigger on some object. in that i am first creating obj1,obj2 which are lookup in obj1. But when i am running trigger I am getting exception System.DmlException: Insert failed. First exception on row 0; first error: INVALID_PARTNER_NETWORK_STATUS, invalid status for partner I have also tried it with apex script, but same exception i am getting. So anyone come across the same issue? Any pointer/ solution will be appreciated. Thanks, Manjiri
BrettBBrettB

I am...What was the solution Here?

padma sree 17padma sree 17
Hi Adi,

I want to transfer cases from one org to another org, how can i map account name and contact name in the subscribed objects.

Please help me.

Thanks in advance.
Sushree Biswal 10Sushree Biswal 10
Hi Adi,
I am facing problem in mapping the lookup field using s2s connection. And I am  not  able to debug the trigger which is fired for the records coming from source org to target org

Please help me.