Variables are used to store data according to the record data types in Salesforce. For example, if the data is string or text, it will be stored in the text data type, and if the data is a mobile number, it will be stored in the number or integer data type. Therefore, before storing any data in a variable, you must define its type.
In this Salesforce tutorial, we will learn to create Variables using Flow. Here, we create variables with a couple of examples, where I will create a variable of the text data type and a variable of the Sobject data type.
Create Variables Using Flow Builder in Salesforce Lightning
In the below examples, I will explain the method of creating variables of text and Sobject data type, and you can follow the same steps to create variables with other data types.
- Create a Text variable to store the user name.
- Create a Sobject variable to store data objects like lead, account, and contact.
Create a Text Variable using Flow Builder in Salesforce
To create a text variable using the Salesforce Flow builder, login to your Salesforce developer account and follow the below steps.
1. Navigate to Salesforce Lightning’s setup page, click the settings icon, and then select Setup from the options in the dropdown.
2. On Salesforce Lightning’s setup page, go to the Quick Find box and search, then select Flows under the heading Process Automation.

3. In the setup window of flows, click on the button New Flow.

4. To create a new flow, select the Screen Flow option and click the Create button.

5. In the flow builder, click the toggle icon at the upper right and then click the New Resource button.

6. In this window, we must enter the following details to create a text variable.
- In the field Resource Type, select the option Variable.
- Enter the API name for the new variable. In this example, I named the variable Var_Username because this variable will store the username.
- Enter the description for the new variable.
- Select the data type Text.
- To make this variable available outside the flow, activate the checkboxes Available for input and Available for output.
- At last, click on the Done button.

As we click on the Done button, the text data type variable will be created and it will be visible in the Variables section under the heading Resources.

In this way, we can create a text variable in the Salesforce flow by following the above steps.
Create a SObject variable using Flow Builder in Salesforce
To create an SObject variable using the Salesforce Flow builder, log in to your Salesforce developer console and follow the below steps.
In this example, I will create an object variable that stores the values of the object. This variable can be created only when the data type is Record.
1. To navigate to Salesforce Lightning’s setup page, click on the settings icon and select the Setup option.
2. On Salesforce Lightning’s setup page, go to the Quick Find box and search, then select Flows under the heading Process Automation.
3. On the setup page of flow automation, click on the button New Flow.

4. In this window, we have to select a flow type; in this example, we will use the option Screen flow. After this, click on the Create button.

5. Now enter the following fields to create a Sobject variable.
- In the field Resource type, select the option Variable.
- In the field API name, enter a relevant API name for the variable. For example, I have entered it as Sov_contact for the SObject variable that will store contact data.
- In the Data Type field, select the option Record.
- Select the object that you want to store in this variable. In this example, I have selected the Contact object.
- To make this variable available outside the flow activate the checkboxes Available for input and Available for output.
- At last, click on the Done button.

As we click on the Done button, the text data type variable will be created and it will be visible in the Variables section under the heading Resources.

In this way, we can create a Sobject variable in the Salesforce flow by following the above steps.
Create Variables Using Flow Builder in Salesforce Classic
In the below steps, we will go through the process of creating variables using the flow builder. In this example, we will create a boolean data type variable.
Now, switch to the Salesforce Classic edition in your developer console and follow the below steps.
1. Navigate to the Setup page of Salesforce, and for that, click on the Setup tab.
2. On the Setup page of Salesforce Classic, go to the Quick Find box in the left sidebar and search Flows. Then, under the heading Workflow and Approvals, select flows.
3. In the Flows setup window, click on the button New Flow.
4. In this step, select the option Screen flow and click on the Create button.

5. In the Salesforce flow builder, click the toggle icon on the left side, then click the New Resource button.
6. In this window, enter the below fields to create a boolean variable.
- In the field Resource type, select the option Variable.
- In the field API Name, enter a relevant API name for the variable. For this boolean variable, I have entered the api name as User_IsActive.
- Enter the description for the variable.
- Select the data type Boolean.
- Select the default value as True or False. If you select false, it will appear as {!$GlobalConstant.False}.
- To make this flow available outside the flow, click on the checkbox Available for input and Available for output.
- At last, click on the Done button.

As we click on the Done button, the boolean variable will be created and visible in the flow builder’s manager tab under the heading Resources.

In this way, we can create variables using flow builder in Salesforce Classic by following the above steps.
Conclusion
In Salesforce, creating variables in flow is important to store data in the variable correctly because different types of variables store different types of data. In this Salesforce tutorial, we have learned about the process of creating variables using the flow builder in Salesforce.
The above example might have helped you understand the method of creating custom variables with different data types. By now, you will be able to create the custom variable using the flow builder in your Salesforce instance.
You may like to read:
- What is Record Trigger Flow in Salesforce
- How to Create Platform Event-Triggered Flow in Salesforce
- How to Create Workflow Rule in Salesforce
- How to Create and Deploy Scheduled-Trigger Flow in Salesforce
- How to Create a Salesforce Screen Flow
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.