How and When to Make Variables Available for Input or Output in Flow

How and When to Make Variables Available for Input or Output in Flow

In Flow, a variable is a container that holds a piece of information. Variables can start as empty (null) or with a default value. During the flow, their values can be referenced or updated as needed. Variables can be made available outside the flow, allowing their values to be set from outside. These values can also be accessed elsewhere outside the flow. Let's see how and when to make variables available for input or output in Salesforce Flow.

Variable Availability Outside the Flow

It is possible to make a variable available for input or output from the Availability Outside the Flow section.

Variable Available for Input

Available for Input

When a variable is available for input, a value can be set at the start of the flow.

Most screen flows have at least one variable available for input. For example, when launching a screen flow using an action, you need to create an input variable called recordId. This allows the system to pass the record to your screen flow. If you are calling your flow from other sources such as a Lightning page, Experience page, button, REST API, or another flow, you may need to create additional input variables.

In order to pass a value to a variable, you must mark it available as input. For instance, Delimiter and TextValues are input variables of a flow that we are calling as a subflow.

Input Values of a Subflow

Available for Output

When a variable is available for output, it can be accessed by another place outside of the flow.

Although you will use this option less frequently than making variables available for input, there are scenarios where it is necessary. For example, multiple flows might share the same set of actions. Instead of building the same logic over and over again, you can build the logic once (as an autolaunched or screen flow) and call it as a subflow. In this case, you will likely pass a value to the subflow and receive an output in return. To enable this, you must mark the variable as available for output.

For instance, the flow that you saw before receives Delimiter and TextValues as input, and then returns TextCollection as the output.

Variable Available as Output

Let's explore another example using a REST API. Below is a callout to launch a flow via the REST API. As shown, we are passing input values, which correspond to four different variables marked as available for input.

Now, let's look at the output values of the callout. NewCaseNumber, NewCaseTeamMembers, NewCaseId, NewContentDocumentLinks, and NewContactRoles are five different variables marked as available for output.

Why Not Make All Variables Available for Input and Output?

Now you know the differences between available for input and available for output. You might be wondering, why not mark both options for all variables in the flow?

First off, it can be confusing when calling the flow from another place. For example, here it looks like you can/should pass values for all those variables. However, in fact, the flow requires the work_order variable only. The same applies to the output values of the flow.

Many Input Variables

Secondly, you wouldn’t want all variables to be set from outside, as this could compromise security. Most importantly, marking variables as available for output makes them easily accessible through developer tools. Therefore, unless absolutely necessary, avoid marking variables as available for output.

For instance, let's say that you have a public screen flow that displays the subject and status fields of a Case record. It seems harmless, right? However, if you mark your variables as available for output, anyone could use developer tools to view all the field values, including sensitive personal information like phone numbers, email addresses, and home addresses.

Output Values of a Public Screen Flow

Therefore, unless it is necessary, do not mark variables available as output.

Read this post to learn the best practices for passing parameters to public screen flows.

Be the first to comment

Leave a Reply

Your email address will not be published.


*