Getting Started with Salesforce Flow – Part 78 (Auto Forward Records to a Connection)

Getting Started with Salesforce Flow – Part 78 (Auto Forward Records to a Connection)

Last Updated on November 22, 2021 by Rakesh Gupta

To understand how to solve the same business use case using Process Builder. Check out this article Getting Started with Process Builder – Part 10 (Auto forward Records to a Connection).

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.)


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 Salesforce 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 Salesforce Flow to solve the above business requirement. To solve this requirement, we will use the After-save Record-Triggered Flow. Check out this article to understand why we are using after-save record-triggered flow for this scenario. 

Before proceeding you have to understand the below-mentioned objects in 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 using Salesforce Flow. 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.

Let’s begin building this automation process.

Guided Practice (We-do):

There are 4 steps to solve Martin’s business requirement using Salesforce Flow. We must:

  1. Find partner network connection Id
  2. Creating a custom label to store opportunity id
  3. Lightning Flow Steps:
    1. Define flow properties for record-triggered flow
    2. Add a decision element to check the lead source
    3. Add a create records element to forward opportunity record to a connection

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.

  1. Click Setup | Developer Console
  2. In the Query Editor, run the following SOQL query
    1. select ConnectionName, Id from PartnerNetworkConnection where ConnectionStatus=’Accepted’
  3. Make sure to copy Connection Id.

SOQL Query - To get Partner Network Connection Id

Step 2: Creating a Custom Label

Create one custom label to store the ID of the connection a record is shared with.

  1. Click Setup.
  2. In the User Interface, type Custom Labels.
  3. Click on the New Custom Label button.
  4. Enter Short Description the Name will auto-populate.
  5. Now enter the Acme Corp Connection Id in the Value.
  6. Click Save.

Step 3.1: Lightning Flow – Define Flow Properties For After-Save Flow

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Record-Triggered Flow option and click on Next and configure the flow as follows:
    1. How do you want to start building: Freeform
    2. Object: Opportunity
    3. Trigger the Flow When: A record is created or updated
    4. Set Entry Criteria
      1. Condition Requirements: None
    5. Optimize the Flow For: Action and Related Records
  5. Click Done.

Never try to write entry criteria in a Record-Triggered Flow. Why? Check out this article.

Step 3.2: Salesforce Flow – Using Decision Element to Check the Lead Source

Now we will use the Decision element to check the lead source to ensure that it is equal to Partner Referral.

  1. Under Toolbox, select Element.
  2. Drag-and-drop Decision element onto the Flow designer.
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Under Outcome Details, enter the Label the API Name will auto-populate.
  5. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!$Record.LeadSource}
      2. Operator: Equals
      3. Value: Web
  6. 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.

  1. Under Toolbox, select Elements. Drag and drop Create Records onto the canvas.
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
    2. How Many Records to Create: One
    3. How to Set the Record Fields: Use separate resources, and literal values
    4. Object: Connection History
    5. Set Field Values for the Connection History
    6. Row 1:
      1. Field: ConnectionId
      2. Value: {!$Label.Acme_Corp_Connection_Id}
    7. Click Add Row
    8. Row 2:
      1. Field: LocalRecordId
      2. Value: {!varTOpportunityId}
  3. Click Done.

In the end, Martin’s Flow will look like the following screenshot:

Once everything looks good, perform the steps below:

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. API Version for Running the Flow: 53
  5. Interview Label: Record-Trigger: Lead Before Save {!$Flow.CurrentDateTime}
  6. Click Save.

Almost there! Once everything looks good, click the Activate.

Proof of Concept

Now onwards, if a business user creates a new Opportunity record with Lead Source other than the Web, then Salesforce Flow will automatically share it with Partner Network Connection Acme Corp.

  1. 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:Auto Share Opportunity with Connection
  2. The Salesforce FLow automatically shared the new Opportunity with partner network connection Acme Corp.

Formative Assessment:

I want to hear from you!

What is one thing you learned from this post?  How do you envision applying this new knowledge in the real world?

Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.

Proofreader: - Frances Barrera
Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.