Skip to main content

Run a Flow Within a Flow

Learning Objectives

After completing this unit, you’ll be able to:

  • Minimize your work by using the Subflow element.
  • Create a flow that runs within another flow.
  • Configure a referenced flow’s variables to pass data back to the parent flow.
Note

This badge is one stop along the way to Flow Builder proficiency. From start to finish, the Build Flows with Flow Builder trail guides you through learning all about Flow Builder. Follow this recommended sequence of badges to build strong process automation skills and become a Flow Builder expert.

The Power of Laziness

Believe it or not, one of the most important qualities that an admin can have is laziness.

You read that right! If you need to make a change in your Salesforce org that affects four different flows, would you rather update four flows or only one? It sounds like magic, but you too can overcome obstacles like unnecessary work through the power of laziness.

For example, Flo’s organization has four flows that post the same message to Chatter. Whenever something about that Chatter post changes, she updates the duplicated element in all four flows. Flo cringes at the thought of doing so much duplicate work. Fortunately, there’s another element, one that we haven’t used yet: the Subflow element. 

Using the Subflow element in a flow (the parent flow) allows you to reference another flow (the child flow) to run it within the current (parent) flow. The idea of making changes in just one flow instead of all four has Flo pretty excited. Plus, with fewer flows, there are fewer opportunities for something to be overlooked or misconfigured.

Flo asks you to build a separate flow for the Chatter post. She plans to replace the duplicate elements in four separate flows by using the new child flow in their place. Then, if something related to the Chatter post changes, Flo can update the single child flow instead of updating all four separate flows.

Flo Smith relaxing on a fancy lounger, being fanned by a palm leaf, thinking about a flow.

Input and Output Variables

The variables in a child flow are special. Have you noticed the Available for input and Available for output settings when you create variables? Those settings enable variables to carry input from the parent flow to the child flow and carry output from the child flow back to the parent flow.

In the New Resource window, the Availability Outside the Flow section has two options: Available for input and Available for output.

But why send data to and from a child flow? In Flo’s example, the child flow posts to Chatter on the parent flow’s triggering record, so the child flow needs that triggering record’s Id. A child flow can’t access the $Record global variable in the parent flow, so the parent flow needs to send it to the child flow. And if the parent flow needs to know the ID of the Chatter post created by the child flow, the child flow needs to send that ID back to the parent flow.

You define variables as available for input or output in the child flow.

  • To receive data from a parent flow, the child flow needs a variable that’s available for input.
  • To send data back to the parent flow when the child flow finishes, the child flow needs a variable that’s available for output.
  • If you don’t need to send data in either direction, you don’t need any input or output variables.

Diagram corresponding to the preceding description

Create a Subflow Element

To run a flow within another flow, first you create the parent and child flows. Then you add a Subflow element to the parent flow.

Create the Child Flow

  1. Create a flow and select the Autolaunched Flow type.
  2. Create a text variable:
    1. API Name: userMentionID
    2. Available for input: checked
  3. Create another text variable:
    1. API Name: postTargetID
    2. Available for input: checked
  4. Create one more text variable:
    1. API Name: chatterPostID
    2. Available for output: checked
  5. Create a text template:
    1. API Name: chatterBody
    2. Body: @[{!userMentionID}], please review this record.
    3. In the Body editor, change "View as Rich Text" to "View as Plain Text".
  6. Add an Action element:
    1. Action: Post to Chatter
    2. Label: Chatter Mention Post
    3. API Name: Chatter_Mention_Post
    4. Message: chatterBody
    5. Target Name or ID: postTargetID
    6. Under Advanced, select Manually assign variables
    7. Feed Item ID: chatterPostID
  7. Save the flow. For Flow Label, enter Post to Chatter.
  8. Activate the flow.

Create the Parent Flow with a Subflow Element

  1. Create a record-triggered flow:
    1. Object: Case
    2. Trigger the Flow When: A record is created or updated
    3. Condition Requirements: All Conditions Are Met (AND)
    4. Condition: Priority, Equals, High
    5. When to Run the Flow for Updated Records: Only when a record is updated to meet the condition requirements
    6. Optimize the Flow for: Actions and Related Records
  2. Add a Subflow element:
    1. Referenced Flow: Post to Chatter
    2. Label: Post to Chatter
    3. API Name: Post_to_Chatter
    4. Enable the postTargetID field and select $RecordId.
      The New Subflow window, selecting $Record then OwnerId in the userMentionID field.
    5. Enable the userMentionID field and select $RecordOwnerId.
      Make sure you scroll down and select OwnerId, not Owner (Group) or Owner (User).
      Note: When a referenced flow has no variables set to be available for input, you won’t see the Set Input Values section.
  3. Save the flow. For Flow Label, enter Case Priority is High.

Now, whenever the record creation needs change, Flo updates only the single child flow. The score is Laziness—1, Overwork—0!

Consider The Following

Keep these quirks in mind when you work with subflows.

  • The Subflow element can reference only Autolaunched flows and screen flows.
  • In a screen flow, you can reference only another screen flow.
  • If you reference an inactive flow, it runs only for users who have the Manage Flows permission.
  • If a child flow has multiple versions, the parent flow runs the child flow’s active version. If a child flow has no active version, the parent flow runs the latest version.

Resources

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities