Flow Resources

 

        • What are Flow Resources?
        • How do we use them?


Variable

Most programming languages have a variable type, nothing special here - except there are some variations with Flow.

Variables

Variables are just a place to temporarily store some information. They have a name and store a value. Normally they just store one piece of information like the variable "v_temp" that can store the number 75 as it's value. We can have dates, text, percentages and other types for our variables.

The important thing about variables is in the name (the value can vary or change). We may add values to the variable or change it's value part way through our flow.

Collection Variables

In Flow, we can also have a collection variable.

One that contains many values. eg "c_temp"

Record Variables

In Flow, we can also define a variable that is of type record and we can store an entire record in the variable.

For example, we may have a record variable named "r_contact" which can store a contact record. These are used in screen flows with loops that collect data to create a number of new records.

Record Collection Variables

A collection of records can be stored in a record collection variable. Our collection of contacts could be named: "rc_contacts" and contain a number of contact records.

When we use a record variable like in the example above, we add each record variable to our record collection variable (inside the loop) and then when finished adding records create the records from the collection (outside the loop).



Constant

A constant is like a variable but its value cannot be changed. The value stays the same throughout the flow.

The value for "pi" is 3.14 (approx) and never changes. This is an example of a constant.



Formula

There is a large range of formulas that can be used in Flows. From simple math formulas to complex string handling formulas.

v_outsidetemp - v_windchill could be a formula used to calculate the "feels like temperature".

Flow has some restrictions on the type of formulas, not all Salesforce formulas are currently supported.

The full list of Salesforce functions is here: Formula Operators and Functions

The restrictions are listed here: Flow Formula Considerations

Text Template

Text templates are a special type, a block of text. These are ideal to format the message body of an email and you can also include merge fields in the text block.

Choice

Choices are used when you want to present the user with choices eg: Yes/No/Maybe.

Record Choice Set

Choices can also be populated from a set of records. Perhaps you want to have a picklist where the user selects a record to relate to the existing one. eg Account/Contact.

Picklist Choice Set

A final type of choice is from an existing picklist. If you want to present a picklist of choices and have an existing picklist on the record you are working with you can directly reference that picklist. The advantage of this method is if you later add values or remove values from the picklist, your choices will be automatically updated.

Stage

The final resource type is the stage. This refers to the stage of the flow and you can define this how you want. Perhaps you have a 5-page flow and you want to indicate to the user how far through the flow they are, you can reference the stage. This is a little-used resource but you can get more information here:  Show Users Progress Through a Flow with Stages


About Data Types


When defining variables in a Flow, each one has a specific data type.

This is the list of supported data types in Flow.

  • Text

  • Record

  • Number

  • Currency

  • Boolean

  • Date

  • Date/Time

  • Picklist

  • Multi-Select Picklist

  • Apex-Defined


About Input / Output Variables


When you are creating variables, there are two checkboxes at the bottom of the page.

These refer to how this variable can be accessed from outside the flow.


Available for Input

If your flow is to be run from a button on a record page then you will probably want to pass the current record (eg Opportunity) through to the flow to perform some actions on it. For this, you would define a text variable called "recordId" (exact capitalization is very important) and select the checkbox for input.

What this means is the variable recordId is going to recieve the Opportunity ID as an input.

recordId is a special name reserved for passing the ID of the current record across to the flow.

(note the capital letter "I")



Available for Output

If your flow solution contains one main flow that calls other sub-flows then you may want the main flow to have a variable eg "recordId" and mark this as Available for both input and output. This way the main flow can receive the recordId from the page and pass it across as an output to the sub-flow. In the subflow element (within the main flow), you configure the variable to be passed in as follows:


Sub-flow element:


Main flow configuration of the sub-flow element:


Sub-Flow configuration:

In the sub-flow itself, you also configure the recordId variable as input (to receive the value). This way you now have the recordId of the record that started your main flow and you can also perform actions on it in the sub-flow (if needed). Perhaps you want to update the record at the end of the sub-flow?



About Global Constants


Global Constants can be used anywhere in your flow and they always have the same value.

They are useful for testing True/False and Empty string conditions.

GLOBAL CONSTANTSUPPORTED DATA TYPES

{!$GlobalConstant.True}

Boolean

{!$GlobalConstant.False}

Boolean

{!$GlobalConstant.EmptyString}

Text



Null Versus Empty String

At run time, {!$GlobalConstant.EmptyString} and null are treated as separate, distinct values. For example:

  • When you leave a text field or resource value blank, the value is null at run time. If you want the value to be treated as an empty string, set it to {!$GlobalConstant.EmptyString}.
  • For a flow condition, use the is null operator to check whether a value is null. If the condition compares two text variables, make sure that their default values are either correctly set to {!$GlobalConstant.EmptyString} or left blank (null).



About Global Variables



There are a large number of Global Variables that are available in your flows too.

When you are doing an assignment, you can use these (depending on the data type you are assigning to):



$Flow

    • CurrentDate
    • CurrentDateTime
    • FaultMessage
    • CurrentStage
    • InterviewStartTime
    • InterviewGuid
    • CurrentRecord

$Api

    • Can't see much use for these

$Label

    • Field
    • PageLayout
    • RecordType

$Organization

    • Name
    • Address
    • Latitude
    • Longitude
    • Phone

$Permission

    • Can't see much use for these

$Profile

    • Description
    • name
    • UserType

$Setup

    • Can't see much use for these

$System

    • Can't see much use for these

$User

    • Address
    • FirstName
    • LastName
    • IsActive

$UserRole

    • DeveloperName
    • Id
    • Name

Exercise: Adding Resources to your Flow


Adding Variables and Constants


Aim

For this exercise, we will be creating a new Screen flow and adding several variables a constant and a formula.

We will then display the values of them so we can see our results.

Method

Start with a new Screen flow:


Select New Resource:


Select Variable:


Our first variable is recordId, we will use this to store the ID of the record that initiated this flow:

(make sure to tick the checkbox Available for input - as this variable gets its value from outside the flow)


Create another variable and name it 
r_contact (for a Record variable), with a data type of Record and select the Contact object:

(this variable can hold one contact record)


Next, we want a constant (a non-changing value), of type number and a value of 7:

(this value will be added to today's date to create a follow-up date)

Finally, we want a new resource that is a Formula of type date and the formula value is Today() + {!c_followUpDelay}:

(this is to calculate the new follow-up date by adding today's date plus the follow-up delay)


Click the + sign below the Start button and add a Get Records element:

(we want the full contact record, not just the ID so we can display the contact's First name)

 


There is more ...


Next, we want a Screen element to display our results (click + and add one):



Give the screen a label and API name:


Drag a Display Text component on our screen:


In this component, we want to display the values of our variables, constant and formula.

Give the component an API Name (display_values) and paste this text into the right panel:

Value of c_followUpDelay = {!c_followUpDelay}
First Name of r_contact = {!r_contact.FirstName}
recordId value = {!recordId}
f_dateToFollowUp = {!f_dateToFollowUp}




Click Done to finish configuring that component.

Your flow should now look like this:




Save your flow:


Now open a new tab and open any contact record. Copy the ID from the URL (everything between Contact/   and /view) - should be 18 characters.

(note: your value will be different to the one shown here)

PS: All contact records have a prefix of 003.



Go back to your flow tab and click the debug button.

Paste the 18 char ID into the recordId field and click Run:


If everything went well, you should now see the results:

  1. The constant c_followUpDelay = 7
  2. The First Name of r_contact = (depends on the contact you selected)
  3. The recordId of this contact = the same as you pasted into the debug screen
  4. The formula f_dateToFollowUp = 7 days after you ran the flow.



Exercise: Adding Formulas


Formula Limitations

Before we start, there are a few limitations that you need to be aware of when using Flow Formulas:

  • A flow formula can contain up to 3,900 characters.
  • When you paste a formula, make sure that the apostrophes and quotation marks are straight ('') and not curly (‘’). Otherwise, you get a syntax error when you save the flow.

Flow has some restrictions on the type of formulas, not all Salesforce formulas are currently supported.

These functions aren’t supported in a flow formula:

  • GETRECORDIDS
  • IMAGE
  • INCLUDE
  • ISCHANGED* (Record Update Trigger from Winter 21 has similar functionality)
  • ISNEW* (Record Update Trigger from Winter 21 has similar functionality)
  • PARENTGROUPVAL
  • PREVGROUPVAL
  • PRIORVALUE* ($Record__Prior in Spring '21)
  • REQUIRE SCRIPT
  • TIMENOW
  • TIMEVALUE
  • VLOOKUP



Create Formulas

We will create the following formulas in this exercise:

  • The current date
  • The current date and time
  • A date 7 days from now
  • The date/time two hours from now
  • The date/time 30 minutes from now
  • A string that concatenates two fields

First, we will create the formulas, then we will add them to a screen.


Step 1: Create a new Screen Flow


Create a new flow of type Screen Flow.

Now you can start adding the formulas:


The Current Date

Create a new resource of type Formula.

Give the resource a new API Name: f_currentDate

Give it a description: The current date

Select Date as the Data Type

In the Formula field, Select the $Flow global variable Current Date





The new formula value will be added:



Click Done to save our formula.



The Current Date and Time

Create a new resource of type Formula.

API Name eg: f_currentDateTime

Description: The current date and time

Data Type: Date/Time

Select the $Flow global variable CurrentDateTime



Click Done to save our formula.



A Date 7 days from now

Create a new resource of type Formula.

API Name: f_dateIn7Days

Description: What is the date in 7 days?

Data Type: Date

Select the $Flow global variable

Select Current Date

Add "+ 7" to the formula to indicate we want to add 7 days to the current date.

{!$Flow.CurrentDate} + 7




Click Done to save our formula.


The date/time two hours from now

Create a new resource of type Formula.

API Name eg: f_timein2hours

Description: What is the time in two hours from now?

Data Type: Date/Time

Select the $Flow global variable

Select Current Date/Time

Add "+ (2/24)" for the two additional hours






The date/time 30 minutes from now

Create a new resource of type Formula.

API Name: f_timein30mins

Description: What is the time in 30 minutes from now?

Data Type: Date/Time

Select the $Flow global variable

Select Current Date/Time

Add "+ (30/1440)" for the extra 30 minutes




A string that concatenates two fields

Create a new resource of type Formula.

API Name: f_userFullName

Description: What is the users Full Name?

Data Type: Text

Select the $User global variable





Select $User First Name




Enter: "& ' ' &"   - this joins first name and last name with a space between the single quote marks

Select $User Last Name

The final formula will look like this:



{!$User.FirstName} & ' ' & {!$User.LastName}     (note there is one space between ' and ')



Step 2: Add a Screen Element





Drag a Display Text component to the canvas




Select the Display Text component and give it an API Name: Display_Values

Click in the text box below and add this text:

The Current Date is:
The Current Date and Time is:
The Date 7 Days from now is:
The time in 2 hours is:
The time in 30 mins is:
My User Name:


Now click next to The Current Date is: (1) and then click on Insert a resource ... (2) so you can insert your formula.



Select your formula:



You should now have the formula reference (merge field) inserted into the Display Text as follows:




Repeat this process to add the merge fields for the other formulas.

When you are finished it should look like this:




Click Done

Ok you got an error! You have not named the screen yet.



Click the header and give the screen a name: Display Formula Values

Click in the API Name field and it will be automatically populated.


Step 3: Save the Flow

Name your flow: formulas

Your finished flow is quite simple, it has only one element.



Step 4: Run your flow

Click debug to run your flow and see the results:

There are no input parameters so just click Run.




If all went well, you will see something like this:






Step 5: Celebrate!

Yay! You did well, take a break.






Great resource on using Formulas in Flow



Exercise: Adding Text Templates


 Text Templates are used where you need to create a large block of text - for example in the body of an email message.

Text Templates are another resource type.

Create a new Screen Flow.

Add a New Resource and select Text Template.



Save the template.

Next, Add a new element - an Action:



Filter by Email (1) and select the Send Email action (2):



Fill out the parameters for the Send Email action and select the Text Template that you just created for the email body:



For the recipient email address, add your own email to the Email Address (comma-separated) section and make sure you click Include:

Please use your own email address!


Save your flow as "Text Template" and click debug then run.

There will be nothing displayed on your screen when it runs but check your email for the message:





















No comments: