Subflows from Record-Triggered Flows in Salesforce

Share the love

In the Winter ’22 release, Salesforce gave us the option to call a subflow from a record-triggered flow. Previously, the parent flow had to be other flow types such as scheduled flows. This new feature now allows us to break our flows down into bit-sized chunks (great for some of our flows that have grown a life of their own and you get lost trying to follow the path). It also allows reusability of flows (who doesn’t love that!). Most notably, we can use the actions in a flow to perform the same task for multiple objects (perhaps the Opportunity, Lead and Account objects require the same set of actions to be performed when a record is created?).

In my example below, I have a flow that is triggered after a record is saved on the Opportunity object (note: you cannot call a subflow on a record-triggered before save flow). This flow will run every time a record is created or edited on an Opportunity (but this can be any object you want). From this parent flow, I can branch off into different flows based off decisions. For example, I may want to make decisions based on each record type I have on the Opportunity object. From these decisions, I can add different subflows. The subflow will be the powerhouse that will contain the logic and data manipulation. Essentially, my parent flow is just a shell that follows a path to a subflow based on criteria.

Creating the Subflow

Let’s start with creating our subflow. In the Setup menu, search for Flows. Once in the flow main screen, click New Flow. Select Autolaunched Flow (No Trigger) and click Next. Choose a layout style (I like Auto-Layout).

Now it’s time to build your subflow! You can build it anyway you like, but you won’t have direct access to the record as you do with Record-Triggered Flows. Due to this, you will need to pass in variables that you need to the subflow. Let’s create some variables.

Go to New Resource on the left side pane. Choose Variable and give it an API Name of your choosing. Select the data type of the variable (in my example, I have selected Text but if you wanted to pass the Record to the subflow, choose the Record data type). This variable will only be available in your subflow if you select Available for input. This allows you to pass in a variable from another flow (which will be our parent flow). Conversely, you may want to pass back a variable to the parent flow. In order to pass your variable back to the parent flow, you will need to select Available for output.

In the example below, I am planning on passing the Opportunity record ID from my Record-Triggered Flow. For this reason, I have chosen Available for input.

Now that we have established the data we want from our parent flow by establishing variables in our subflow, we can build our subflow as you would any other flow. In my example, I will update the Stage field value in the record. I added an Update Records element and filtered the record based off my Opp_Record_ID variable.

Finally, save your flow and select Activate.

Parent Flow Set Up

Now we need to set up the parent flow to call our subflow. Go back to the main flow screen and select New Flow. Select Record-Triggered Flow, click Next and choose a layout style.

The next screen sets up how your flow will be triggered. Select the object in which you want to access the record data from. The trigger can be any of the options that suit your use case. I’m going with the most popular trigger; A record is created or updated, and I’ll opt for running my flow after the record has been saved.

Now that we are in the flow designer, we can start adding the actions we need. For this example, I am going to have a Decision element to filter which subflow to run based on record-type. Next, we’ll add a Subflow element.

Select your subflow name (mine was called Call Subflow). On the bottom of the screen, you will see Set Input Values. All the variables that you selected Available for input in your subflow will be available to select in the Subflow element. Toggle the Include button to be active and set the variable you want to pass in to the subflow. In my example, I wanted the Record ID to be passed in.

And we’re done! Once you have completed the actions of your parent flow, you can Save and Debug it. If the Debug action is called from the parent flow, it will also log through to the subflow. Happy flowing!

Share the love

Leave a Reply

Your email address will not be published. Required fields are marked *