Set Your Productivity on Steroids by Creating Subflows

Set Your Productivity on Steroids by Creating Subflows

Last Updated on August 11, 2022 by Rakesh Gupta

Salesforce Flow is one of the most used declarative tools to automate business processes in Salesforce. Most of us usually create a new flow for each requirement. That not only is not a best practice, but, in the long run, it is a highly unproductive and unsustainable approach to managing process development.

Furthermore, you risk hitting the governor limit if you create multiple flows on one object. Therefore, my suggestion is to create as minimum as possible flows on each object. 

With the recent release, it is possible to invoke an autolaunched flow (as subflow) from an After-Save record-triggered flow. With Subflow, you can reuse logic in flows. Build one autolaunched flow (subflow); call it from multiple flows or multiple action groups in the same flow. By using this method – of reusing a flow – you can save time, keep the governor’s limit at arm’s length and boost your productivity! 

Business Use Case

Pamela Kline is working as a System Administrator at Gurukul on Cloud (GoC). She must update the Account custom field, Out of Business, to True if an Opportunity Stage is updated to Closed Lost. 

There are various ways, as listed, in which you can solve the preceding business requirement:

  • With one record-triggered flow on the opportunity object 
  • Apex Trigger
  • and much more

As of now, the very first solution looks good. After a few weeks, however, Pamela received another similar requirement – to update the Account custom field, Out of Business, to True if Account Rating is Not Interested. Oh, no! Not again!

Now she has to re-write the same logic by creating a Record-Triggered flow on Account object; this is tedious and time-consuming, to say the least. Because, as you can see, in both the requirements, we are updating Account custom field, Out of Business, to True. How about reusing the existing logic with Account Flow? Let us do it!

Automation Champion Approach (I-do):

There are a few possible solutions for the above business scenarioTo solve the preceding business requirement (Update Account custom field, Out of Business, to True if an Opportunity is updated to Closed Lost), we will use the concept of subflow.

Subflow means launch another flow that’s available in your org. A flow that is launched by another flow is called the referenced flow.

We have to create two flows for this, as follows:

  • The first autolaunched flow (It is invoked by record-triggered flow) it is used to update account field.
  • Another flow (A record-triggered flow) is placed on the Opportunity object, and it will fire only when an Opportunity Stage is updated to Closed Lost

The benefit of using this approach is that if you get a requirement in the future – to update the Account custom field, Out of Business, to True if Account Rating is Not Interested – then, you call the autolaunched flow from your Account record-triggered flow without adding another Record Update on Account flow.

Guided Practice (We-do):

  1. First of all, create a custom field (Out_of_Business__c) data type Checkbox, on account object.
  2. Make sure to add value Not Interested for Rating (drop-down) field on the account.

Step 3: Define Subflow Properties

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows, then click on the New Flow.
  4. Select the Autolaunched Flow (No Trigger) option.
  5. Click on Create.

Step 4: Add Action – Update Records

The next step is to update the account Out of Business field to True. We will use the Update Records element. 

  1. On Flow Designer, click on the +icon and select the Update Records element.
  2. Enter a name in the Label field; the API Name will auto-populate.
  3. For How to Find Records to Update and Set Their Values select Specify conditions to identify records, and set fields individually
  4. Object: Account
  5. Select All Conditions Are Met (AND)
  6. Set Filter Conditions
    1. Row 1:
      1. Field: Id
      2. Operator: Equals
      3. Value: {!varT_AccountId}
        1. Where varT_AccountId is a text variable of type Input and Output.
  7. Set Field Values for the Opportunity Records
    1. Row 1:
      1. Field: Out_of_Business__c
      2. Value: {!$GlobalConstant.True}
  8. Click Done.

In the end, Pamela’s Subflow 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: 56
  5. Interview Label: Subflow: Account Update
  6. Click Save.

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

Step 5: Define a Master Record-Triggered Flow to Call a Subflow

  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, click on Create 
    1. Object: Opportunity
    2. Trigger Opportunity Flow When: A record is created or updated
    3. Set Entry Criteria
      1. Condition Requirements: None
    4. Optimize the Flow For Action and Related Records
  5. Click Done.

Step 6: Using Decision Element to Check if Opportunity is Closed Lost or Not

Now we will use the Decision element to check the StageName to ensure that it is equal to Closed Lost. 

    1. On Flow Designer, click on the + icon and select the Decision element. 
    2. Enter a name in the Label field; the API Name will auto-populate.
    3. Under Outcome Details, enter the Label; theAPI Name will auto-populate.
    4. Condition Requirements to Execute Outcome: All Conditions Are Met (AND)
      1. Row 1:
        1. Resource: {!$Record.StageName}
        2. Operator: Equals 
        3. Value: Closed Lost

Step 7: Add Subflow: Account Update Action

We will use the Subflow: Account Update action to update the account’s Out of Business field.

  1. On Flow Designer, below the Closed Lost node, click on the +icon and select the Action element.
  2. Search and select the Subflow: Account Update from the drop-down menu
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Set Input Values
    1. varT_AccountId: {!$Record.AccountId}
  5. Click Done.


In the end, Pamela’s Record-Triggered 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: 56
  5. Interview Label: Opportunity After-Save
  6. Click Save.

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

Proof of Concept

Next time, when a user updates the opportunity Stage to Closed Lost, both the Flows will fire and update the Account Out_of_business__C to True, as shown in the following screenshot:

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? Feel free to share in the comments below.

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

4 thoughts on “Set Your Productivity on Steroids by Creating Subflows

  1. With above don’t you have to create a new “master process” on opportunity if say you want to invoke another process if “Opportunity Owner ” changes – ie you will end up with two master processes on Opportunity – rather than 1 as is “best practice”

Leave a Reply

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