Learning Salesforce Visual Workflow and Process Builder(Second Edition)
上QQ阅读APP看书,第一时间看更新

Creating a variable

A variable is used to store a value. You can use the variable throughout your Flow; for example, while creating a record, performing an update, or with delete operations.

Here is business scenario: Robby Williams is working as a system administrator for Universal Containers. Currently, he is developing a Visual Workflow and wants to create a variable to store customer names.

To create a variable in your Flow, follow these instructions:

  1. Navigate to Setup | Build | Create | Workflow & Approvals | Flows.
  2. Click on the New Flow button; it will open the Flow canvas for you.
If you are using Flow for the first time, then it will pop up a welcome page. On the bottom of the page, you can see the Don't Show Again checkbox. If you want the Flow page to load faster, then select this checkbox.
  1. Navigate to the Resources tab and double-click on the Variable option that is available under the CREATE NEW section, as shown in the following screenshot:
    This will open a window for you, where you have to enter the following details:
    • Unique Name: Enter a unique name. The name must begin with a letter, and use only alphanumeric characters and underscores. Uniqueness applies only to elements within the current Flow. In this case, enter VarTCustomerName.
    • Description: Write some meaningful text so other developers/administrators can easily understand why this variable has been created. When you select the Variable in the Explorer tab, then this description appears in the Description pane.
    • Data Type: This determines which types of value a variable can store. Select the data type of Text. The following are the available data types for a variable:
      • Text: This is used to store any combination of letters and numbers.
      •  Number: This is used to store any numbers.
      • Currency: This is used to store currency.
      • Date: This is used to store the date.
      • DateTime: This is used to store the date with the time.
      • Boolean: This is used to store either true or false.
      • PicklistThis is used to store picklist values. It supports the ISPICKVAL() function in Flow formulas.
      • Picklist (Multi-select): This is used to store multi-select picklist values.
    • Scale: This is only available when the data type is set to Number or Currency. Scale is the number of digits to the right of the decimal point.
    • Input/Output Type: This defines whether a variable is available within the Flow or can also be accessed outside the Flow. The different input/output types are as follows:
      • Private: This variable can be allocated and used only within the Flow.
      • Input Only: This allows you to set a variable at the start of the Flow using Visualforce controllers, URL parameters, or subflow inputs.
      • Output Only: This means that you can access a variable's value from Visualforce controllers and other Flows.
      • Input and Output: This means that you can set a variable's value at the start and access its value outside the Flow. In our case, select Input and Output.
      • Default Value: This allows you to set a default value for the variable. You can either manually enter the value or use the drop-down list to assign the value of a Flow resource as the default. In our case, select {!$GlobalConstant.EmptyString} available under GLOBAL CONSTANT. This will look like the following screenshot:

4. Once you are done, click on the OK button.

For best practice, in this book we will be using VarT as the prefix for the Text variable, VarN for Number , VarC for Currency , VarD for Date , VarDT for DateTime , and VarB for the Boolean variable type.