Flow: How To Use Variable / Collection Variable

Variable is definitely one of the first things mentioned in any Programming 101 courses, and that is no difference in Salesforce Flow.

What Is Variable?

flow variable

You can think of a variable as a place holder. In your flow, you can alter the value stored in the variable and use it later.

For example, you set up hotkeys to call people and set 1 as calling your mom. Whenever you press one, the phone will call your mom automatically. The key 1 here is like the variable, and calling your mom is the value stored in the variable.

What Is Collection Variable?

flow collection variable

A collection variable is then a place holder for a group of values.

Following the same example, you set 2 as calling your dad, your sister, and your brother all at once. Since key 2 stores multiple values, we will call it a collection variable.

Note that in Salesforce Flow, the collection variable has orders – which means if you set the order as dad, sister, and brother, this will be the calling sequence every time you hit 2.

What Is Record (Single) Variable?

Then it comes to the more complicated part – Record variable and Record collection variable. Both of them can store many fields, so some of you might think this is a group values. We will not dive into the details, but think about the value here as “the number of records“.
Record (Single) Variable can only store one record, but all the fields of this record can be stored in the same variable.

Imagine on your phone, you set key 3 to show the contact information of your boss. Once you click 3, you can only see your boss’ info showing up, but you can see her/his email, phone, address, etc. Then key 3 will be like a record (single) variable.

What Is Record Collection Variable?

Similar to above, but this time you can store all the fields of several records.

Now you set key 4 to show the contact information of team which has 10 people. When you click 4, you can see all 10 people showing up, and then you can further check into their email, phone, address, etc. Then key 4 will be like a record collection variable.

Check Out How Variable/Collection Can Be Used In Real Cases!
Use Case: Clone Any Objects with Related Lists with Flow
"Clone with related" is an amazing feature which sadly is ...
Use Case: Simple Loop Example in Flow
Earlier we have published the how-to-guides on Loop and Counter, ...
Use Case: Simple Counter Example in Flow
Earlier we have published the how-to guides on Loop and ...
Use Case: Mass Update Records From Related List #2
In this article we introduced the magical ids variable to ...
Loading...

Official Salesforce Help Article On Variable

Subscribe
Notify of
guest

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Alex

Love your tutorials!

Quick question, when using a collection variable, how do I access any of the elements within a variable?
Say I have 100 different products, and 100 different costs. I’d like to just make 2 variables, CVProduct and CVCost, and match up CVProduct[1] to CVCost[1], CVProduct[2] to CVCost[2], and so on.

The alternative is creating 200 different variables…but there’s no way I have to do that, right?

Last edited 1 year ago by Alex