Skip to main content
Geschätzte Zeit

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 triggering record 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:
    • API Name: userMentionID
    • Available for input: checked
  1. Create another text variable:
    • API Name: postTargetID
    • Available for input: checked
  1. Create one more text variable:
    • API Name: chatterPostID
    • Available for output: checked
  1. Create a text template:
    • API Name: chatterBody
    • Body: @[{!userMentionID}], please review this record.
    • In the Body editor, change "View as Rich Text" to "View as Plain Text".
  1. Add an Action element:
    • Action: Post to Chatter
    • Label: Chatter Mention Post
    • API Name: Chatter_Mention_Post
    • Message: chatterBody
    • Target Name or ID: postTargetID
    • Under Show advanced options, select Manually assign variables.
    • Feed Item ID: chatterPostID
  1. Save the flow. For Flow Label, enter Post to Chatter.
  2. Activate the flow.

Create the Parent Flow with a Subflow Element

  1. Create a record-triggered flow:
    • Object: Case
    • Trigger the Flow When: A record is created or updated
    • Condition Requirements: All Conditions Are Met (AND)
    • Condition: Priority, Equals, High
    • When to Run the Flow for Updated Records: Only when a record is updated to meet the condition requirements
    • Optimize the Flow for: Actions and Related Records
  1. Add a Subflow element:
    • Select the Post to Chatter flow.
    • Label: Post to Chatter
    • API Name: Post_to_Chatter
    • Enable the postTargetID field and select Triggering Case > Case ID.
      The Subflow panel, selecting Triggering Case then Owner ID in the userMentionID field.
    • Enable the userMentionID field and select Triggering Case > Owner ID.
      Make sure you scroll down and select Owner ID, not Owner ID (Group) or Owner ID (User).
Note

When a referenced flow has no variables set to be available for input, you won’t see the Set Input Values section.

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

Teilen Sie Ihr Trailhead-Feedback über die Salesforce-Hilfe.

Wir würden uns sehr freuen, von Ihren Erfahrungen mit Trailhead zu hören: Sie können jetzt jederzeit über die Salesforce-Hilfe auf das neue Feedback-Formular zugreifen.

Weitere Infos Weiter zu "Feedback teilen"