STEP 1) Enabling Salesforce to Salesforce
Enable the Salesforce to Salesforce in both the org. Follow below step to do that
Setup--> Salesforce to Salesforce --> Salesforce to Salesforce Setting.
Then click on Edit button checked the Enable checkbox.
NOTE:- you should have "Manage Connections" access on profile level.
Step 2) Connection Setup
To setup connection you need to open "Connection" Tab. Then Click on New Tab.
Then Select Account and Contact then click on "Save & Send Invite". You also need to set Owner. Owner will get notification if any error will come.
When you will click on "Save & Send Invite" button Contact (Amit Chaudhary) will get a email like below
Then copy above URL and login by other org user.
Then other org user need to accept the invitation.
Now Connection is established but no object is shared.
Step 3) Publishing Objects
Now we need to publish or subscribe the standard or custom object. To publish the object you need to go to first Org and click on "Publish/Unpublish" button.
Then select the object and click on save.
You can select the field from Publish Object related list. Select the object and click on Object name.
Step 4) Subscribing Objects
Now got back to receiving org and click on "Subscribed Objects" related list.
Then map the object.
Now we need to map the field. Go to "Subscribed Object" related list and select object and map field.
Now connection is setup.
Step 5) Using the Shared Connection
To share the record we have two way one is Manual and 2nd is by programming.
- Manual Sharing Records
Then select the connection and click on Save button.
Records will be automatically created in the target environment if auto-accept for the object is enabled
- Programmatic sharing records via Apex
Sample Code.
trigger ShareAccountS2S on Account (After update) {
Set <Id> setAcc = new Set<Id>();
for(account acc : Trigger.New){
if(acc.Active__c == 'Yes'){
setAcc.add(acc.id);
}
}
if(setAcc.size() >0) {
Id NetworkId ;
String connName ='ForBlog'; // Plz add connection Name
list<PartnerNetworkConnection> conns = [select id from PartnerNetworkConnection where ConnectionName = :connName ];
if(conns.size()>0) {
NetworkId = conns[0].id;
}
if( NetworkId != NULL ){
string relatedRecords = 'Contact' ;
list<PartnerNetworkRecordConnection> recordShares = new list<PartnerNetworkRecordConnection>();
for(id accId : setAcc )
{
recordShares.add(new PartnerNetworkRecordConnection(
ConnectionId = networkId,
LocalRecordId = accId,
RelatedRecords = relatedRecords
));
}
insert recordShares;
}
}
}
Set <Id> setAcc = new Set<Id>();
for(account acc : Trigger.New){
if(acc.Active__c == 'Yes'){
setAcc.add(acc.id);
}
}
if(setAcc.size() >0) {
Id NetworkId ;
String connName ='ForBlog'; // Plz add connection Name
list<PartnerNetworkConnection> conns = [select id from PartnerNetworkConnection where ConnectionName = :connName ];
if(conns.size()>0) {
NetworkId = conns[0].id;
}
if( NetworkId != NULL ){
string relatedRecords = 'Contact' ;
list<PartnerNetworkRecordConnection> recordShares = new list<PartnerNetworkRecordConnection>();
for(id accId : setAcc )
{
recordShares.add(new PartnerNetworkRecordConnection(
ConnectionId = networkId,
LocalRecordId = accId,
RelatedRecords = relatedRecords
));
}
insert recordShares;
}
}
}
Related Post
1) Salesforce to Salesforce Overview
2) https://developer.salesforce.com/page/Best_Practices_for_Salesforce_to_Salesforce
Thanks
Amit Chaudhary
@amit_sfdc