Big Idea or Enduring Question:
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.
One key pain point in the Salesforce-to-Salesforce connection is sharing data manually. If you want to automate the data sharing process, then you have to use the Apex code. In this case, we’re able to accomplish this with a couple of declarative tools and no coding required.
(Please note that Salesforce to Salesforce Connections is only available in Classic at this time. We’re not sure if Salesforce plans to support this in lightning. We can switch to classic to set up the connection for this tutorial.)
Objectives:
After reading this blog post, the reader will be able to:
- Understand the Salesforce-to-Salesforce connection capabilities
- Understand which options are available for sharing records with partners
- Share data seamlessly with automation
- Get exposure to Lightning Flow
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’s required to share all opportunities that didn’t originate from the “web” lead source. Considering the volume of opportunities, Martin needs to automate this.
Automation Champion Approach (I-do):
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 the below-mentioned objects in Salesforce
- PartnerNetworkConnection: -This object represents a Salesforce to Salesforce connection between Salesforce organizations.
- 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. In this tutorial, we’re going to set up a Salesforce to Salesforce connection with a fictitious company, Acme. To set this up, please follow the instructions listed here.
This article will help you to understand how to auto-forward records to a Connection and how to launch a Flow from Process Builder. If you’re unfamiliar with the flow and its capabilities, I’d recommend checking out our tutorials on Flow listed here.
Before discussing it, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it.
Guided Practice (We-do):
There are 4 steps to solve Martin’s business requirement using Flow and Process Builder. We must:
- Find partner network connection Id
- Creating a custom label to store opportunity id
- Lightning Flow Steps:
- Define flow properties for auto-launched flow
- Add a text variable to store an opportunity record data
- Add a create records element – share the record with the auditor
- Process Builder Steps:
- Define process properties
- Define evaluation criteria
- Define process criteria
- Add action – flows
Step 1: Find Partner Network Connection Id for Acme Corp
The first step is to find out the Connection Id for partner network Acme Corp. One possible workaround is to use the Developer Console.
- Click Setup | Developer Console
- In the Query Editor, run the following SOQL query
- select ConnectionName, Id from PartnerNetworkConnection where ConnectionStatus=’Accepted’
- Make sure to copy Connection Id.
Step 2: Creating a Custom Label
Create one custom label to store the ID of the connection a record is shared with.
- Click Setup.
- In the User Interface, type Custom Labels.
- Click on the New Custom Label button.
- Enter Short Description the Name will auto-populate.
- Now enter the Acme Corp Connection Id in the Value.
- Click Save.
Step 3.1: Lightning Flow – Define Flow Properties
- Click Setup.
- In the Quick Find box, type Flows.
- Select Flows then click on the New Flow.
- Select the Autolaunched Flow (No Trigger) option and click on Next and configure the flow as follows:
- How do you want to start building: Freeform
- Click Done.
Step 3.2: Lightning Flow – Add a Text Variable to Store Opportunity Id
- Under Toolbox, select Manager, then click New Resource to store Opportunity Id.
- Input the following information:
- Resource Type: Variable
- API Name: varTOpportunityId
- Data Type: Text
- Default Value: {!GlobalConstant.EmptyString}
- Check Available for Input
- Check Available for Output
- Click Done.
Step 3.3: Lightning Flow – Create Records – Forward Opportunity Record to Acme Corp
The next step is to auto-share the Opportunity records with Partner connection. For this, we will use the Create Records element. We’ll essentially duplicate our current record into the established connection org by pointing our record to a new record in the connected Salesforce instance.
- Under Toolbox, select Elements. Drag and drop Create Records onto the canvas.
- Input the following information:
- Enter Label the API Name will auto-populate.
- How Many Records to Create: One
- How to Set the Record Fields: Use separate resources, and literal values
- Object: Connection History
- Set Field Values for the Connection History
- Row 1:
- Field: ConnectionId
- Value: {!$Label.Acme_Corp_Connection_Id}
- Click Add Row
- Row 2:
- Field: LocalRecordId
- Value: {!varTOpportunityId}
- Click Done.
In the end, Martin’s Flow will look like the following screenshot:
Once everything looks good, perform the steps below:
- Click Save.
- Enter Flow Label the API Name will auto-populate.
- Click Show Advanced.
- API Version for Running the Flow: 50
- Interview Label: Auto Forward Record to Connection {!$Flow.CurrentDateTime}
- Click Save.
Almost there! Once everything looks good, click the Activate button.
Our next task is to create a Process on the Opportunity object to launch a Flow, only when an Opportunity Lead Source is not equal to the Web.
Step 4.1: Define Process Properties
- Click Setup.
- In the Quick Find box, type Process Builder.
- Select Process Builder, then click New.
- Name the Process and click the Tab button. The API Name will populate.
- As a best practice, always input a description.
- The process starts when A record changes.
- Click Save.
Step 4.2: Define Evaluation Criteria
- Click on the Add Object node to begin selecting the evaluation criteria.
- Select the Opportunity object from the dropdown list.
- Start the process only when a record is created.
- Click Save.
Step 4.3: Define Process Criteria
- Click the Add Criteria node to begin defining the process criteria.
- Name the criteria.
- The criteria should execute actions when the conditions are met.
- Set Conditions
- Row 1
- Field: Opportunity| LeadSource
- Operator: Does not equal
- Type: Picklist
- Value: Web
- Row 1
- Select All of the conditions are met (AND).
- Click Save.
Step 4.4: Add Action – Flow
- Below Immediate Actions, click Add Action.
- For Action Type, select Flows.
- Name the action.
- Select the flow we just created – Auto Forward Record to Connection.
- Set Flow Variables:
- Row 1:
- Flow Variable: varTOpportunityId
- Type: Field Reference
- Value: Opportunity | Id
- Row 1:
- Click Save.
In the end, Martin’s Process will look like the following screenshot:
Almost there! Once everything looks good, click the Activate button.
Proof of Concept
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.
- Now create a new Opportunity with the 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.
Formative Assessment:
Identify a custom object in your org that should be shared based on the settings in a related object and create an autolaunched flow that will share the records without actual manual sharing
Post a picture of the sharing on Twitter @automationchamp, #AutomatedSharingwithFlow