Understand, Create & Use Variables in Salesforce Flow!

Understand, Create & Use Variables in Salesforce Flow!

Last Updated on February 10, 2022 by Rakesh Gupta

Enjoy enhanced flow-building experience starting with Spring’19 release. Salesforce is at it again! – replacing Cloud Flow Designer (Canvas to design and build the flows) with a faster and robust tool – Flow Builder. It streamlines the process of – (1) flow building; and (2) maintenance – with a simplified user interface. 

In light of the above, the first question that comes to mind is – what is the difference between Cloud Flow Designer and Flow Builder? Well, that is the very purpose of this article! – to give you an overview of Flow Builder and explain the difference.

I have started a series on Salesforce Flow to unearth basic concepts and help you to understand the power of FlowIf you haven’t subscribed to my blog yet, please do it now and get new blog post notifications in your inbox. You can do so by navigating to this page –  Join Our Mailing List

Salesforce Flow is a tool that allows you to automate business processes by building applications known as Flows. Flow can be used to collect, createupdate, and delete information in Salesforce. Flows can also execute logic, interact with the Salesforce database, call Apex classesand guide users through screens for collecting and updating dataOnce you design and develop Flows to fulfill the business requirement(s), grant access to Flows to your users. Let’s start with a business use case:

Business Use Case

Edward Backhouse is working as a System administrator at GurukulOnCloud. Edward is new to Flow Builder and was motivated to learn more about it after reading this article – Want to be an Early Adopter of the New Flow Builder? Welcome Aboard!. After reading the article, the following two questions arose in Edward’s mind:

  1. When to use Salesforce Flow vs Process Builder?
  2. What is a Variable and how to create one using Flow Builder? 

Salesforce Flow vs Process Builder

These two tools have their own use cases – i.e., each tool is better suited to solve a specific kind of requirement or problem. Let’s start with a question – if you want to go to the moon you would more likely use a rocket, as opposed to walking, as a means of transportation. But suppose, instead of going to the moon, you tone down your goal and decide to go to the North Pole. In that case, yes, walking there may take ages but you may still be able to do so.

Now take a pause and think why I gave you this example?  The above example explains the limitations of a human’s capabilities – for, a human can’t fly. The limitation is key here – if you understand platform limitations then, it will go a long way in helping you to find the right tools and design appropriate solutions. 

Process Builder Salesforce Flow
Can’t be used to delete records. Can be used to delete records.
Not all objects are supported by Process Builder. Many objects are accessible using Salesforce Flow. For example – OpportunityContactRole, UserDevice, etc.
Can be triggered when a record is created or edited. Can be triggered when a record is created, edited, or even deleted.
Can’t be triggered after a successful login.  Can be triggered when a user successfully logs into Salesforce.
Not possible to save the newly created record ID (If it is created using the Record Create element). Possible to store the newly created record ID in a variable; so that, you can reference it in a flow later.
Good for the intermediate use case. Like this one. Much more power to implement complex logic. Like this one
Can’t be used to capture user input(s). Can be used to capture the user input(s) and later process it based on your business use case.
Can be Schedule to run daily, weekly or once. 

Now if you want to deepen your understanding of the power of Process Builder and Salesforce Flow – check out my articles here

Having understood the difference between Process Builder and Flow, let’s take the discussion forward and focus on Edward’s second question –  What is a Variable, and how to create one using Flow Builder? 

What is a Variable and how to create one using Flow Builder?

What is a Variable? – It is a container that stores information. If so then, what role does a Variable play in Flow?

Let us take a real-life example. Suppose if someone requests you to store two pounds of rice. The first thing you will do is to look for a container that is appropriate to store the rice – more likely than not, it would not be a fruit basket with holes! Similarly, suppose you are traveling, and want to carry some frozen food. In this case, you will look for a specifically designed bag/container to carry frozen food.

variable

Notice that, in the above example, a container needed to store rice is different than a container needed to store frozen food. So, different containers are needed to store different types of items – A Ziploc bag may not be as desirable a container to store liquid – milk or juice – like a glass or a plastic bottle/box.

Variables in Flow are no different – different types of variables store different types of data. We call it – Data types. If a variable stores text, it will need a Text Data Type; if it stores numbers, it will need a Number Data Type. Therefore, before storing any data into a variable you must define its type. Here is the list of Variable Types in Flow.

Now some hands-on – let us create few variables:

We will create different types of variables as follows:

  1. A text variable to store the First Name
  2. An SObject Variable to store one lead record data

Creating a Text Variable

A text variable is used to store alphanumerics (character, digit, or both) – such as Rakesh or 18c Power House Road). To create a text variable in the Salesforce Flow, follow the instructions below:  

  1. Login in to your developer org.
  2. Navigate to Setup (Gear Icon) | Setup | PLATFORM TOOLS | Process Automation | Flow.
  3. You’re now on the Flow management page. Based on your current org setting, you may see the following buttons: Flow Management page
    1. New Flow – Use this button to create a Flow in the new Flow Builder.
    2. New Flow in Cloud Flow Designer – Use this button to create a Flow in the classic (old) Cloud Flow Designer.
  4. Now follow the steps as shown in the video to create a Text variable:
  5. Once you’re done click on the Done button. 
  6. Currently, in the Flow Builder, it is not possible to change the Data Type once you create a variable – check out the video for more details:
  7.  Well done! You have just created your first variable using Flow Builder.

Creating an SObject Variable

SObject variable is used to stores field values for a Salesforce record. To create an Sobject variable – that stores a lead record fields value – follow the instructions below:  

  1. Login in to your developer org.
  2. Navigate to Setup (Gear Icon) | Setup | PLATFORM TOOLS | Process Automation | Flow.
  3. You’re now on the Flow management page.
  4. Now follow the steps as shown in the video to create an SObject variable:
  5. Once you’re done click on the Done button. 
  6. Navigate to Manager tab to access variable and resources which you added to Flow, as shown in the following screenshot: Variables and Resources
  7. There! After creating an SObject variable, aren’t you feeling like a Pro?! 

Assignments

      1. Create a variable that stores the Date of birth. 
      2. Create a variable that is used to store multiple Opportunities records and their fields. 
      3. Create a variable that is used to store one Opportunity record and its fields.
      4. Create a variable to store the annual revenue of the customer. 
Proofreader: - Munira Majmundar
Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

Preferred Timing(required)

17 thoughts on “Understand, Create & Use Variables in Salesforce Flow!

  1. Hi Rakesh Sir,
    Can we pull Records/fields From two differents Objects in one variable like {!Opportunity.amount} and {!Passenger.RegistrationFees_c} ? If Yes, Can you please Guide me on the procedure to do that?

  2. Hi Rakesh,

    In Assignment 2 ,it is saying “Create a variable that is used to store multiple Opportunities records and their fields.”
    Don’t we check the checkbox named “Allow Multiple Values” since we are creating multiple records and their fields?
    Since in the screenshot I have seen the checkbox is unchecked.

    Thank you

  3. Under Assignment 2 – I am trying to create Sobject variable to store multiple records. How do we specify fields? or how to specify one to multiple opportunity

  4. Hi Rakesh,

    What did you mean by creating a Sobject? Isn’t it just a Record Variable that you’re creating?

    Is sobject just a naming convention that you use when creating these type of variables?

    Thanks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Automation Champion

Subscribe now to keep reading and get access to the full archive.

Continue reading