You need to sign in to do that
Don't have an account?

Accepting S2S records programmatically
Hi all,
I would like to know if anyone had run into a need to programmatically accept a shared record ( via Salesforce to Salesforce ), avoiding the manual accept. Example of this is when I need to share an account with related opportunities, but opportunities have multiple lookups and are not auto accepted on the receiving org. I need to be able to auto-accept these programmatically and then re-map the lookups ( the re-mapping is a different matter which I am not concerned about ). The bottom line is: can records forwarded from a source org, which are not auto-accepted on target org, be programmatically accepted?
Any information would be appreciated.
Thank you.
There are many hidden objects which you cannot send through S2S. SO they cannot be automatically accepted.
For e.g you are talking about childs of Opportunity.
OpportunityContactRole
OpportunityLineItemSchedule
You cannot send this through S2S. You have to use DataLoader or other DataMigration tools to migrate those.
As you cannot get the chance to publish those objects through S2S.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
I am talking about objects that CAN be shared through S2S. Not related to opportunity, but opportunities themselves. When I share and Account WITH related standard objects such as Opportunities, Contacts I only see Account auto-accepted because the other objects have too many lookups to the same object and therefore are not auto-accepted. I am looking for a way to auto-accept such records via apex code.
"I am talking about objects that CAN be shared through S2S. "
Go to connections. Click Publish Button. There you can get which objects can be shared through S2S.
When subscribing the objects you have to click Auto Accept checkbox for it. If that checkbox is disabled then those can be auto accepted while sending the master record if you write the following code in apex.
if(objectName == 'Account'){
newrecord.RelatedRecords = 'Contact,Opportunity';
}
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Alright, I would think that this piece of code:
if(objectName == 'Account'){
newrecord.RelatedRecords = 'Contact,Opportunity';
}
would be exactly the same as when forwarding an account record and checking the "Opportunity" and "Contact" related records to be forwarded with that account. I did that already, as well as checking "Auto Accept" on the receiving org. The problem is that under certain conditions the Auto-accept doesn't work. This is from the SF documentation, the conditions for auto-accept:
1. The parent record must already be accepted in the organization.
2. The record must be related as a child to the parent record.
3. The child record cannot have two master records.
4. The child record cannot have multiple relationships to the same parent object.
5. The connection owner must be an active user.
6. The owner of the parent record must be an active user.
The problem is with # 4, on the opportunity object I have a lot of lookups to the same parent object and as a result, when I forward the Account with related Opportunity only the account gets auto-accepted, the opportunity is forwarded but is awaiting manual "Accept" from the user. I want to avoid that and auto-accept those kinds of records.
Okay got it. In that case for multi look ups it is better to transfer those objects singly.
Means transfer account first, then Opportunity along with their oldprimarykey and oldparentids in a text field.
Then in target organisation you can write batch apex script to assign those lookups through the old parent keys.
As I can't think of auto accepting those things through apex.
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Yep, that's what I thought. Re-establishing the lookups is not a problem, there code for that even in the Salesforce to Salesforce Best Practices document from SF. So such records need to be manually accepted when using S2S, unless there is a custom org to org sync implementation such as this:
http://boards.developerforce.com/t5/Apex-Code-Development/Apex-Callouts-to-Apex-Web-Service-Automated-S2S-Possible/m-p/132622#M16915
Thanks Souvik.
http://deepikamatam.blogspot.com/2019/07/salesforce-2-salesforce-connect.html
https://deepikamatam.blogspot.com/2019/07/s2s-file-sharing.html