Welcome to a new series designed to help explain the basic concepts of Salesforce Flow. In this post, we will focus on Flow Variables. As I work with Admin trying to learn Salesforce Flow, I frequently hear something like the following:
If that sounds like you, this series will help you. The reality is Flow introduces many things, as Admins, we may never have had to work with before. I'm going to attempt to bring some clarity to a variety of topics like:
If you're ready to learn, bookmark my site, subscribe to Terry's Tidbits YouTube channel, and let's start mastering Salesforce Flows.
Before we dive into variables, let's start with something more familiar; like our typical bedroom dresser. A dresser has drawers and drawers a great! We can put stuff in them and whenever we need that item, we simply open the drawer and retrieve it. If we're well organized, we would have a drawer for our socks, another drawer for shirts, and perhaps a third for pants or shorts. Each drawer has its purpose. Shirts don't go in the socks drawer; only socks go in the socks drawer.
Variables are also like dresser drawers or fields. They are designed to hold things and they only hold a certain type of thing. A text variable can only store alphanumeric information because when we create a variable, we have to tell it the type of information it's going to hold. This is just like creating a custom field in Salesforce. We have to define the type of data the field will hold.
Let's go a little deeper. A dresser can be sorta like a Salesforce record and its drawers are like fields. Maybe we have a Contact dresser and that means we'd have a First-Name drawer, a Last-Name drawer, a Phone drawer, an Email drawer, and so on.
Did you know, one of our Variable types is a record? When you create a variable, you can model it after a Salesforce object. You could think of the record variable as a dresser. All the fields on the Object can be addressed within that Record variable. It's so cool!!
Let's keep going deeper, by exploring the record variable. If we defined it as a Contact record, we'd have a First-Name drawer, a Last-Name drawer, and an Email drawer. The First-Name and Last-Name fields are type Text. That means they can store anything that is an alphanumeric value. The Email drawer is a type called Email. You would never store a First-Name value in an Email drawer. Not only because they don't belong there, but Salesforce won't let us do it. That's because they aren't compatible types.
Now that we've established what a variable is, let's look at the different types we have. Salesforce calls these Data Types. Below is a quick look at the Data Types. Notice how many of these match the Data Type options we have when creating new fields in Salesforce.
|Data Type||What if Holds|
|Text||This is the most common data type and it holds anything alphanumeric based data.|
|Record||This data type allows you to store an entire Salesforce record in it. Let's say I'm making changes to an Account record. I could store that account record in this type of variable and reference it or change its field values whenever I need to.|
|Number||This one is very clear; it storages numbers and you can define how many decimal positions it can have.|
|Currency||This is any form of dollars and cents.|
|Boolean||Think Checkbox. A Boolean is simply a True/False variable. If "checked" it's True. If "unchecked" it's false.|
|Date||This is another easy-to-understand data type. It simply holds a Date.|
|DateTime||Much like the Data data type but it adds the element of Time.|
|Picklist||I'll be honest, I've never used this option. I've always used a Text variable instead but this would store a picklist selection.|
|Multi-Select Picklist||Similar to Picklist but holds multiple picklist selections.|
|Apex Defined||This option is for those unique situations when what you need is NOT one of the above options. This data type gives us enormous power and flexibility as we can define it, using Apex, to be whatever format we need it to be.|
There they are. Those are your various Data Types currently supported in Salesforce Flow.
I'm so glad you asked that question! We want to use a variable anytime we need to keep track of something. For example, let's say we had a Get Records element in our flow and perhaps we need to do calculations that require us to know how many records it returned. A numeric variable would allow us to store that number so we can use it throughout the flow.
Variables allow us to temporarily store information so we can reference them anytime we need to. They do not need to be a field value, although they can represent that, and we don't have to save the variable to a Salesforce record. We simply use it and discard it when the flow is finished.
Because all my readers are very smart people I'm sure you're next question is, How do I create one of these variable? You can simply press the New Resource button or link wherever you see it within your Flow. You can always find it in the left Toolbox panel. Once selected, it will take you to the screen below.
Click on the Resource Type picklist and select Variable.
There are lots of Resource Types available. We'll talk about some of them later in the series.
Next, give it an API Name. I highly recommend you check out my Flow Naming Convention post and adopt a naming convention for everything that requires a Name in Flows. You'll thank me later. I preface all my variable names with "var". It makes it easy to find and reference them later.
Also, be a good Admin and give your variable a Description. That will help you and anyone who follows you to understand its use.
Now we're ready to select the Data Type. Remember our dresser conversation and how we had a sock drawer that only socks go into? That's what we're defining here. What type of data do we want to store in this variable? In our use case, we're counting records which means we need this to be a number variable so we'd select Number.
When selecting a Data Type, some additional field(s) may appear on the form. A Number data type will display a field asking you how many Decimal Places do we need to store. If you select Record, you'll be asked which Object to model the variable after.
Most of the Data Types have the option to set a Default Value. It doesn't have to be set unless it makes sense to do so.
Just a couple more things to understand when defining a variable.
If my Variable needs to only hold a single value, I would not check the box. But let's say it's an Account Record Variable and I need it to hold multiple records. Then simply check the box.
Here's another example. If I only want one sock in the drawer, it's unchecked. If I want to store multiple socks, it would be checked.
If I need to pass a variable out of this Flow, perhaps to another Flow, I would mark the Available for Output checkbox.
Most of the time your variables are used only within the Flow and will not need either of these checkboxes checked. To be clear, that was a "most of the time" statement; not an all the time nor a none of the time statement.
Flow Variables are drawers. They simply hold what they are designed to hold. They can hold a single item or they can hold many items but those items must be of the same type.
We will look into how we can work with data in the next release in this series. That will cover the Get, Update, Create, and Delete elements (the pink ones). I hope you'll stay tuned.
If you found this helpful, remember to watch the video presentation on my YouTube channel. Like, Subscribe, Follow, and Share my content with your friends. Thanks, everyone.