Auto Forward Records to a Connection Using Salesforce Flow

Auto Forward Records to a Connection Using Salesforce Flow

Last Updated on May 11, 2023 by Rakesh Gupta

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 Opportunities 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: {!$Record.Id}
  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!
Preferred Timing(required)

26 thoughts on “Auto Forward Records to a Connection Using Salesforce Flow

  1. Hey Rakesh,

    Thanks for this! However, I think I missed a step to get the details for Step 3.3:
    Row 2:
    Field: LocalRecordId
    Value: {!varTOpportunityId}

    Can’t seem to find “{!varTOpportunityId}”?

    Thanks in advance!

  2. Hi Rakesh, when I create a record the flow is meeting the criteria and working properly in classic, but when I switch to Lightning UI all the opty even if condition is not met , all opty records are flowing. Can you please assist regarding this

  3. Hi Rakesh,
    Thank you, this article has helped me a lot. I have used the same logic to sync leads from one org to another , but there is an error in flow as below, kindly suggest me to resolve this.

    Error Occurred:

    This error occurred when the flow tried to create records: INVALID_PARTNER_NETWORK_STATUS: invalid status for partner network operation.

    1. There are various reason to get such error
      – The specified partner network status is invalid for the specified template field.
      – LocalRecordId attribute of “PartnerNetworkRecordConnection” is incorrect

  4. got this to work on Case thanks to your steps great write up! now the business wants to expand this to include any attachments to be shared on the case. any words of wisdom on how to share related attachments?

    kindest – Paul

      1. Hi,
        Currently, when a case has the owner set to a specific Queue, i have a Process builder that kicks off a flow and shares the case over via Salesforce to Salesforce connection ( this part is where your tips and tricks REALLY helped out). now the business would like for any attachments to also share over. i’m thinking i could have my flow to a fast lookup to see if the are any attachments with the Case ID but i’m a bit foggy on the specifics.

  5. Hi Rakesh,

    Is there a way to share the public post on a case from one SF instance to another SF instance (S2S) via Flow? I’m able to share the case but the Public post isn’t getting shared. Need your help

          1. Thanks for the reply :), I have done this but still the second one “is not connected to anything” is still stopping me to activate

  6. This was very easy to follow, good job. A question I have is how to scale this up to a real world scenario. For example, you wouldn’t want to forward an opportunity or another related record like a contact, without the account too. In your example, if you just transfer the opportunity, it becomes orphaned. So, what is necessary to scale this up to either associated with the an account that has already been forwarded too or to create this missing account?

  7. We do this now but use a Record Lookup to get the Connection ID. This requires that the Account name be on the record you are forwarding, assuming you might have multiple Salesforce to Salesforce connections.

Leave a Reply

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