How to Create Variables Using Flow Builder in Salesforce

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.

Create Variable using Salesforce Flow builder

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

Create Variable using flow in Salesforce

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

Use Flow builder to create Variables in Salesforce

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

How to create variable for Salesforce flow

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.