Salesforce-to-Salesforce can be used to share the data both within and across Salesforce organizations. Salesforce-to-Salesforce is a natively supported feature of the Salesforce Platform and easily enables two dealing partners to share relevant data records in real time. It allows you to share records with your business partners that use Salesforce and get real-time updates on the shared data. For example, you can share Opportunity and Lead data with business partners. Key Pain Points in Salesforce-to-Salesforce connection is to share the data manually. If you want to automate the data sharing process, then you have to use the Apex code. Let’s start with a business use case
Business Use case
Martin Jones is working as a System administrator at Universal Containers (UC). His company as well as another company (Acme Corp), has established Salesforce-to-Salesforce. He has received a requirement from higher management to auto-share the new opportunities with Acme Corp if opportunity Lead Source doesn’t equal to Web.
Solution for the above business requirement
There are multiple solutions possible for the above business scenario. We will use Flow and Process Builder to solve the above business requirement. Before proceeding you have to understand below-mentioned objects in Salesforce
A) PartnerNetworkConnection: -This object represents a Salesforce to Salesforce connection between Salesforce organizations.
B) PartnerNetworkRecordConnection: – This object represents a record shared between Salesforce organizations using Salesforce to Salesforce.
If you haven’t enabled Salesforce-to-Salesforce connection and want to do so, then please have a look at An Introduction to Salesforce to Salesforce article published by Salesforce.com
This article will help you to understand how to auto-forward records to a Connection and way to Launch a Flow from Process Builder. Follow the below instructions to create a Flow and Process for the above business requirement
1. To create a Flow, navigate to Setup (Gear Icon) | Setup | PLATFORM TOOLS | Process Automation | Flow.
2. Now click on the New Flow button; it will open the Lightning Flow Designer for you. Now create one Text variable VarT_OpportunityId to store the Opportunity Id. We will use this variable in the flow, as shown in the following screenshot:
Likewise, create one more Text variable VarT_ConnectionId to store the ID of the connection a record is shared with. To get the Partner Network Connection Id one possible workaround is to use the Developer Console. Click on Setup (Gear icon) | Developer Console and run the below SOQL query
select ConnectionName,id from PartnerNetworkConnection where ConnectionStatus=’Accepted’
It will look like the following screenshot
You can also find this information from Connection Tab. VarT_ConnectionId will look like the following screenshot:
3. The next step is to auto-share the Opportunity records with Partner connection. For this, we will use the Create Records element. Drag-and-drop Create Records Element on the Lightning Flow Designer and fill the details as shown in the following screenshot:
4. Finally, your Flow will look like the following screenshot
5. Click on the Save button and save the Flow with the name Auto Share Opportunity with Connection as shown in the following screenshot
6. Don’t forget to Activate the Flow.
Launch a Flow from the Process Builder
Our next task is to create a Process on Opportunity object to Launch a Flow, only when an Opportunity Lead Source doesn’t equal to Web. To create a Process on the Opportunity object follow the below instructions
1. The next step is to create a process, that will fire when a new user gets created. To do this, Navigate to Setup (Gear Icon) | Setup | Process Automation | Process Builder
2. To create a new process from scratch, click on the New Button available on Process Management page. A popup will appear where you have to enter the Name, API Name and Description as shown in the screenshot below:
3. Once you are done click on the Save button, it will redirect you to Process canvas. Click on Object node to add object, Select Opportunity object, in this case, and set the evaluation criteria, Please refer to the following screenshot for more details
3. Once you are done click on the Save button, it will redirect you to Process canvas. The next step is to define the Process criteria. For this click on Add Criteria node, enter Criteria Name, Set filter conditions (Similar to Rule Criteria in WFR), as shown in the following screenshot
4. Once you are done click on the Save button, it will redirect you to Process canvas. Now we have to add an Immediate action into the Process to Launch a Flow. For this use Flows action. Use Field Picker to select the field Description and Text Entry field to enter a comment or sentence. Please refer the following screenshot for more information
5. Once you are done click on the Save button, it will redirect you to Process canvas. Finally, the Process will look like the following screenshot
Don’t forget to active the Process by clicking on the Activate button
It’s time to test this Process
Now onwards if a business user creates a new Opportunity record with Lead Source other than the Web, then Process Builder will automatically share it with Partner Network Connection Acme Corp
1. Now create a new Opportunity with Name “Burlington Textiles Weaving Plant Generator – Second Phase” and Lead Source blank. Then check the External Sharing related list available on the Opportunity Detail page, as shown in the following screenshot
Process Builder automatically shared the new Opportunity with partner network connection Acme Corp.
Note: – I will suggest you implement this first on your developer org test it and then move it to Production.