Flow Fundamentals: Variables

--

Welcome to Flow Fundamentals! I am Deanne Walters and I love Flow. So, I wanted to create some basic guides breaking down the fundamental concepts behind the tool (this being the first one).

Variables are the building blocks of all Flows, but also the most different part of Flow when compared to Process Builder or Workflows. This article is going to dive into what variables are (and are not) and how they are used in Flow. This is an introduction so some statements will be simplifications of the very complex system that is Flow.

What are variables?

Variables are places to store and use information. I think of variables in Flow like post-it notes. It is a temporary place to put down information before it is relayed somewhere else.

Variables can be populated from outside the Flow (like when launching a Flow from a process). Variables will not remember the information after the Flow is finished so if you want the information saved in Salesforce somewhere it must be saved into a record.

Do variable names matter?

Make sure your variable names are clear, but the variable names do not affect the function of the variable. (This is something I was not sure about when I first started.)

What type of variables are there?

There are four types of variables.

Table of variable types: Variable*, Collection Variable, Record Variable, Record Collection Variable

*Yes, I am using the word variable both as an overall category as well as a specific subtype.

A variable basically holds one field’s worth of data. The data type of a variable could be Text, Number, Currency, Boolean, Date, Data/Time, Picklist, Multi-Select Picklist, or basically anything a field is. These variables work in a similar way to how fields work in that they are made to read and save information of that type.

Record variables are larger variables because rather than holding one field’s worth of information they can hold one record’s worth. When creating the variable, you will have to specify which object this record variable should represent, for example, Contact or Account. If it was a contact record variable it would include all information on the contact record (name, phone, email, address, etc) for one record.

Collection variables like the name implies are groupings of information from multiple variables and record collection variables are groupings of information from multiple record variables.

All variables must be of the same type as the collection; so for a contact record collection variable all variables that are added must be contact record variables you cannot add in an account record variable.

Collection Variables and Record Collection Variables can only be updated by Assignment elements (the Assignment element will be covered in a future article, but here is some information) by either adding or removing variables from the collection. Variables within the collection cannot be changed.

For example, if you have a Collection Variable that contains 1,2,3 and if you wanted to change that to 1,2,4 you would have to remove the 3 and put in a 4 you could not edit the 3 into a 4.

How do I create variables?

Go to the Manager Tab on the left side and click the New Resource button.

Screenshot of Flow: In Manage tab with New Resource button

Under Resource Type select Variable. Under Data Type select the data type you would like to use. If you have selected Record, then you will need to select the object. Once that is selected you can check off the Allow multiple values (collection) box to make it either a Collection Variable or Record Collection Variable.

There are also some other options like Default Values and Available for Input and Available for Output checkboxes that I will be discussing below.

Screenshot of Flow: New Resource variable data entry page

What is Default Value?

If you choose a variable (not Record Variable) then you can set a default value. The default value can either be a hard coded variable (something typed directly in), Global Constant (Empty String, True, False), or Global Variables from the Flow (Current Date, Current Record, etc).

Screenshot of Flow: New Resource text variable data entry page

What is Available for Input and Available for Output?

Available for Input means that an external tool (like a process) can populate the information saved in the variable. Available for Output means an external tool (like a sub-flow**) can pull the information saved in the variable.

**A sub-flow is when you access another Flow within your Flow.

Screenshot of Flow: New Resource record variable data entry page

Do I need to create all my variables at the start of building a Flow?

You might know you need to start with some variables when building your Flow, but you can always create variables as you build. Just make sure to not build repetitive variables.

Should I use this new feature where Flow will create the variable for me?

In Flow before Winter 20 if you wanted a variable you needed to create it yourself. Now Flow will automatically create a variable for you when you create a Get element (the Get element will be covered in a future article, but here is some information). When this feature had recently come out, I had problems using the pre-created variable in multiple record elements. You can use this feature, but just beware if you are having unexpected problems it could stem from this. (For more detail on this feature, see the Winter 20 release notes).

So, while it is more work I generally (but not always) opt for the Choose fields and assign variables (advanced) option; which was the only option before the Winter 20 release.

Screenshot of Flow: Get Record Element with Choose fields and assign variables (advanced) selected

One case when you would want to manually assign variables would be if you want the same action taken by your Flow regardless of if the record already exists or if the Flow has created a new record, then you should definitely specify your own variable so you can use it throughout the Flow. (If you would like an example of how I did this with an application system built in Flow check out this blog post.)

Why should I use Flow?

So you might better understand how Flow works now, but you might not see an application to your organization. Flow has three major strengths compared to other automation tools. The first is that it is just much more powerful than Workflow or Process Builder; you are not constrained by a specific set of records and relationships. So if you need something stronger than those automation tools that is a great use case for Flow.

The second strength is the user interaction with Screen Flows. With Screen Flows you can have users enter information and dynamically move them forward to the place they should be based on what they entered. The information they enter also does not have to be limited to just being saved in one record.

The third strength is the scheduled Flow. You can have a specific automatic process happen at a specified time each day or week.

I have found as I have a better understanding of the abilities of Flow I am better able to apply them to my specific org.

Thank you for reading; feel free to post questions in the comments. I am planning to continue the Flow Fundamentals series let me know what subjects you would like covered.

Thank you to Eileen Kapp, Emily Hicks-Rotella, Avni Patel, Lauren Calderon, and all others for their comments and suggestions.

--

--

Deanne Walters (Database Deanne)

A nonprofit focused Salesforce Admin dedicated to automation and sharing knowledge in an easy to read fashion.