function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BakTBakT 

Salesforce to Salesforce: how to share the related record of the related record

Hi,

 

I am trying to automate the Account sharing on a Salesforce to Salesforce connection. Here's the catch: the Account has a Related record called Object1 and Object 1 has a related record called Object 2. I was able to forward the Account record along with its Object1 records but I can't get to include the Object2 records. How can this be done? Sample code anyone?

Navatar_DbSupNavatar_DbSup

Hi,

 

Programmatic sharing records via Apex

Records can be shared for supported objects programmatically (via triggers, batch process, etc.). Programmatic sharing gives a higher level of control over how you share records and also makes it possible to carry over hierarchy/relationship to the target.

Here is basic code snippet to share a contact record via S2S programmatically.

 PartnerNetworkRecordConnection newConnection =

                     new PartnerNetworkRecordConnection(

                         ConnectionId = networkId,

                         LocalRecordId = newContact.Id,

                         SendClosedTasks = false,

                         SendOpenTasks = false,

                         SendEmails = false,

                         ParentRecordId = newContact.AccountId);

 insert newConnection;

This code can be improved for sharing multiple records and for complex scenarios involving lookup and parent child relationship. See the PartnerNetworkRecordConnection object for more information.

 

For more details go through the link below:


http://boards.developerforce.com/t5/Apex-Code-Development/Salesforce-to-Salesforce-S2S-How-to-recreate-lookup-relationship/m-p/166758/highlight/true#M25217

 

 

BakTBakT

I am able to share the record and its related Object 1 but I am unable to share Object 2 and relate it to Object 1. The issue is that these records have to be shared at the same time and apparently, when you programatically share a record using S2S, it takes some time before the Status goes to active so when I go and forward the Object2, I get an error that says Invalid Status of connection.

alaschgarialaschgari

I'd love to get a solution here, too.

Akanksha Gupta 77Akanksha Gupta 77
can you share your code so that I can help you.