進行状況の追跡を始めよう
Trailhead のホーム
Trailhead のホーム

Create a Variable

Learning Objectives

After completing this unit, you’ll be able to:

  • Create a flow variable.
  • Define input and output variables.

Prepare to Create a Variable

Before you create your variable, figure out what kind of variable you need.

What type of data should the variable store?

First consider what type of data the variable will store, much like you do when you create a custom field.

Data Type Use to store...
Text IDs, descriptions, and other text or long text data.
Record Field values from a record, such as an opportunity. When this data type is selected, you create a record variable.
Number A numeric value.
Currency A currency value.
Boolean A yes/no value, such as whether a checkbox was selected.
Date A date value.

Date/Time

A date and time value.

Picklist

A picklist value.
Multi-Select Picklist Picklist values, separated by semicolons.

How many values should the variable store?

By default, variables store one value that’s compatible with the selected data type. If the data type is Number, the variable stores one numeric value. If the data type is Record, the variable stores field values for one record.

But what if you need to store multiple values in one variable, such as multiple email addresses? When you create a variable, you can enable it to do just that with the Allow multiple values checkbox. When that option is selected, you create a collection variable.

We don’t go into much detail about collection variables in this module, but you can see them in action in the Lightning Flow module and the Build an Account Reassignment Wizard project.

Should the value be available from outside the flow?

Each variable in your flow gets its value from somewhere.

Some variables get their values from inside the flow, such as when the user enters something in a screen component or the flow looks up field values from a record.

Other variables get their values from outside of the flow—namely, from whatever started the flow. For example, if you distribute a flow on an Account record page, you can pass the account’s ID into the flow by using the flow’s input variables. An input variable is a variable that has the Available for input checkbox selected.

If whatever starts the flow should be able to set the value of a variable, make sure the variable is available for input. When in doubt, go ahead and make your variable available for input.

When you configure your variable, you see another checkbox: Available for output. When selected, you’ve created an output variable, which means the value is accessible to something outside the flow. Output variables are too advanced for this module, so we won’t go into much detail about them here. When in doubt, don’t make your variable available for output.

Where do you plan to use the variable?

If you already know where you plan to use the variable, review documentation to see whether that field requires a certain kind of variable.

Tip

Tip

Pay special attention to which data types the field supports and whether it supports single values or collection values.

For example, you need to automatically submit an opportunity for approval from a flow. Rather than using the default approval settings, you need the approval request to be sent to a specific user, so you need to set the Next Approver Ids field. When you look at the reference documentation for the Submit for Approval core action, you see that the Next Approver Ids field only accepts Text collection variables. So you need to store the ID of that user in a Text collection variable.

Create a Variable

  1. Open Flow Builder. From Setup enter Flows in the Quick Find box and click Flows.
  2. Click New Flow.
  3. From the toolbox, click Manager.
  4. Click New Resource.
  5. For Resource Type, select Variable.
  6. Enter an API name and description for your variable.
  7. Select the appropriate data type.
  8. If you want to store multiple values (a collection), select Allow multiple values.
  9. For record variables, select the object whose record values you plan to store.
  10. Identify the variable’s availability outside the flow.

Store Information in a Flow Variable

Once you’ve created a variable, you’ve got a placeholder just waiting for a value to… well, hold. A variable is only as good as the values stored in it, and Flow Builder offers a few ways to populate that variable. Let’s review them.

Set the variable’s default value
If you know what the initial value of the variable should be, set its default value when you create it. The variable keeps that value until it gets overwritten by another element.
Get a value from a record and put that value in the variable
When you configure a Get Records element (which we cover later in this module) or a record choice set, specify the fields to store and which variables to store them in.
Change the variable’s value from an element
The most obvious way to change a variable’s value is with an Assignment element. But other elements let you store values in variables. For example, the Create Records element lets you store the created record’s ID in a variable.
Pass a value in from outside the flow
Depending on how you distribute your flow, you can pass a value into an input variable. For example, if you add the flow to a Contact record page, you can pass the contact’s ID into a flow variable.

Now that we’ve got variables under our belt, let’s dig in to the element categories available in Flow Builder. First up: screens.

Resources

retargeting