Tuesday, 4 October 2011

Setting Up Salesforce To Salesforce

Note: not all records of objects can be shared using Salesforce To Salesforce

First of all lets get the basics out of the way. Follow the steps in

Now for some of the things that Salesforce don't tell you, or it is difficult to find information on.

Regarding the manual sharing records using  "Forward to connection" button. Well I've never personally found this button so if anyone does see this anywhere please tell me.

Sharing Accounts and Attachments Using Code
If you want to share attachments make sure that Setup > Security > 'HTML Documents and Attachments Settings' is not ticked otherwise you won't be able to share certain file types.

Attachments need to have a record associated with it, such as an Account record. You need first of all share the Account record with the other Salesforce orgs first before you can share any Attachments. So of course the donor needs to have Account set up in Connection > Published Objects

Here is some code which will allow you to share the Account and then the Attachment.

List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>();
connMap=[select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection   where ConnectionStatus = 'Accepted'] ;
Account acc =[Select id From Account where id = '<<Account ID>>'];
for(PartnerNetworkConnection network : connMap) {  
     PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
    newrecord.ConnectionId = network.Id;
    newrecord.LocalRecordId =;
    newrecord.SendClosedTasks = true;
    newrecord.SendOpenTasks = true;
    newrecord.SendEmails = true;  
    insert newrecord;

Now that the Account has been shared you can share the Attachment.

Attachment att =[Select id,IsPartnerShared  From Attachment where Parentid='<<Account ID>>'];
att.IsPartnerShared =true;
update att;

If you want to share Attachments manually once the Account has been shared, click edit on the Attachment and a 'Share with Connections' tick box will now be available, tick this and the Attachment will now be shared.

You can setup the recipients to automatically accept shared records. If you do the records will become live automatically in the recipient org, otherwise you need to go to the Account tab, scroll down to  'Accounts from Connections' section, press Go will display any shared Accounts which you can now accept.


  1. Hi Steve,

    Your piece of code seems to be "Unik" on the Web.
    Unfortunately, I'm not a "nerd" and don't understand where I have to plug this code ? Behind a custom button on the display page of the Account Object ?
    Sorry for my English.
    Best regards,


  2. No problem Oliver, please Sign up to my blog and I'll be happy to help


Note: only a member of this blog may post a comment.