Skip to content

Frequently Used Formulas in Salesforce Flows

Frequently Used Formulas in Salesforce Flows.

1. What is Flow Formula Builder?

Flow Formula Builder can be used to create expressions in Formula-type resources as well as Collection Filter and Start elements of a Record-triggered Flow. Choose from a list of functions and operators to construct your expression. Check the formula syntax for each expression as you work to catch errors.

Salesforce Flow Formula Builder
Flow Formula Builder

2. Frequently Used Formulas in Salesforce Flows

For your quick reference, here is a list of some of the most commonly used formulas in Salesforce Flows, along with examples. This list will be updated with more formulas soon.

2.1 Logical

2.1.1 AND

Returns a TRUE response if all values are true; returns a FALSE response if one or more values are false.

AND(logical1,logical2,…)

Replace logical1,logical2,… with the values that you want evaluated.

This formula displays Small if the price and quantity are less than one. This field is blank if the asset has a price or quantity greater than one.

IF(AND(Price<1,Quantity<1),"Small", null)

2.1.2 CASE

Checks a given expression against a series of values. If the expression is equal to a value, returns the corresponding result. If it isn’t equal to any values, it returns the else_result.

CASE(expression, value1, result1, value2, result2,…,else_result)

Replace expression with the field or value you want compared to each specified value. Replace each value and result with the value that must be equivalent to return the result entry. Replace else_result with the value you want returned when the expression doesn’t equal any values.

This formula field displays the month of the last activity or None if there are no activities.

CASE(MONTH(LastActivityDate),
1, "January",
2, "February",
3, "March", 
4, "April", 
5, "May", 
6, "June",
7, "July",
8, "August",
9, "September",
10, "October",
11, "November",
12, "December",
"None")

2.1.3 IF

Determines if expressions are true or false. Returns a given value if true and another value if false.

IF(logical_testvalue_if_truevalue_if_false)

replace logical_test with the expression you want evaluated; replace value_if_true with the value you want returned if the expression is true; replace value_if_false with the value you want returned if the expression is false.

Use this default value formula to set the tax rate of an asset based on the user's city. Create a custom percent field with the following default value:

IF($User.City = "Napa", 0.0750, 
 IF($User.City = "Paso Robles", 0.0725, 
  IF($User.City = "Sutter Creek", 0.0725, 
   IF($User.City = "Los Olivos", 0.0750, 
    IF($User.City = "Livermore", 0.0875, null
    )
   )
  )
 )
)

2.1.4 PRIORVALUE

Returns the previous value of a field.

PRIORVALUE(field)

If an Account Name is changed from DYDC to Test PRIORVALUE(Account.Name) will return DYDC.

2.2 Text

2.2.1 CONTAINS

Compares two arguments of text and returns TRUE if the first argument contains the second argument. If not, returns FALSE.

CONTAINS(text, compare_text)

Replace text with the text that contains the value of compare_text.

IF(CONTAINS(Product_Type__c, "part"), "Parts", "Service")

This formula checks the content of a custom text field named Product_Type and returns Parts for any product with the word “part” in it. Otherwise, it returns Service. 

Creates a link to a URL specified that is linkable from the text specified.

HYPERLINK(url, friendly_name [, target])

Replace url with the Web address, replace friendly_name with the link text, and, optionally, replace target with the window or frame in which to display the content.

The target parameter is optional. If you don’t specify a target, the link opens in a new browser window. Some common target parameters are:

  • _blank – Displays link in a new unnamed window.
  • _self – Displays link in the same frame or window as the element that refers to it.
  • _parent – Displays link in the immediate frameset parent of the current frame. This value is the same as _self if the current frame has no parent.
  • _top – Displays link in the full original window, canceling any other frames. This value is the same as _self if the current frame has no parent.
HYPERLINK("https://www.dineshyadav.com", "DYDC", "_self").

2.2.3 ISPICKVAL

Determines if the value of a picklist field is equal to a text literal you specify.

ISPICKVAL(picklist_field, text_literal)

Replace picklist_field with the merge field name for the picklist; replace text_literal with the picklist value in quotes. text_literal cannot be a merge field or the result of a function.

ISPICKVAL(StageName, "Closed Won")

The above formula will return true if the Stage is "Closed Won"

2.2.4 LEN

Returns the number of characters in a specified text string.

LEN(text

Replace text with the field or expression whose length you want returned.

LEN(EmployeeNumber__c)

This formula returns the number of characters in a Employee Number field.

2.2.5 TEXT

Converts a percent, number, date, date/time, or currency type field into text

TEXT(value)

Replace value with the field or expression you want to convert to text format.

TEXT(Account.Type)

This formula return Text from picklist value

2.2.6 VALUE

Converts a text string to a number.

VALUE(text)

Replace text with the field or expression you want converted into a number.

For example, the formula 10 + VALUE(Text_field__c) produces these results:

If Text field is 100, the result is 110.
If Text field is blank, the result is blank.
If Text field is $100, the result is blank.

2.3 Math

2.3.1 MOD

Returns a remainder after a number is divided by a specified divisor.

MOD(number,divisor)

Replace number with the field or expression you want divided; replace divisor with the number to use as the divisor.

MOD(5, 5) returns 0

MOD(5,2) returns 1

MOD(125, 50) returns 25

2.4 Date & Time

2.4.1 ADDMONTHS

Returns the date that is the indicated number of months before or after a specified date. If the specified date is the last day of the month, the resulting date is the last day of the resulting month. Otherwise, the result has the same date component as the specified date.

ADDMONTHS(date,num)

Replace date with the start date and num with the number of months to be added.

ADDMONTHS (StartDate, 5)

The above formulae adds 5 months to the start date.

2.4.2 DATE

Returns a date value from year, month, and day values you enter. Salesforce displays an error on the detail page if the value of the DATE function in a formula field is an invalid date, such as February 29 in a non-leap year.

DATE(year,month,day)

Replace year with a four-digit year, month with a two-digit month, and day with a two-digit day.

DATE(2022, 10, 16) creates a date field of October 16, 2022.

2.4.3 DAY

Returns a day of the month in the form of a number between 1 and 31.

DAY(date) 

Replace date with a date field or value such as TODAY().

DAY(CloseDate__c) returns the day in your custom close date. Note this doesn't work on date/time fields.

2.4.4 MONTH

Returns the month, a number between 1 (January) and 12 (December) in number format of a given date.

MONTH(date

Replace date with the field or expression for the date containing the month you want returned.

MONTH(TODAY()) returns the current month in a number format. For example, the month of October would be the value “10”

2.4.5 YEAR

Returns the four-digit year in number format of a given date.

YEAR(date

Replace date with the field or expression that contains the year you want returned.

Example: YEAR(Closed_Date__c) will return the year of custom field close date.

3. Flow Formula Considerations

  • These functions aren’t supported in a flow formula.
    • GETRECORDIDS
    • IMAGE
    • INCLUDE
    • PARENTGROUPVAL
    • PREVGROUPVAL
    • REQUIRE SCRIPT
    • TIMENOW
    • TIMEVALUE
    • VLOOKUP
  • In a flow, the CONTAINS function checks all characters within its parentheses. For cross object field references, CONTAINS works like it does in the rest of Salesforce. It checks only the first 250 characters in the reference.
Here’s an example. varContract refers to a record variable that contains the values of a contract record. This formula expression checks only the first 250 characters.

CONTAINS({!varContract.Account.Description}, "description")
This formula expression checks all characters in the field.
CONTAINS({!varContract.Description}, "description")
  • References to global variables in formulas aren’t validated.
  • To reference a platform event in a formula, pass the event data into a record variable in the Pause element. Then reference the appropriate field in that record variable.
  • To evaluate a null field value as a zero value, use the BLANKVALUE function. For example, to evaluate a null value for the NumberOfEmployees field as a zero value, use BLANKVALUE(NumberOfEmployees, 0).
  • 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.

  • A formula returns null if an error occurs when the expression is evaluated, such as:
    • The value that the formula returns doesn’t match its data type.
    • The formula contains an unsupported function.For example, if your formula resource has a data type of Number, the output must be numeric.

4. Where are Formulas Used in Salesforce?

Formulas are used extensively throughout Salesforce. The below table lists some of the key areas:

Feature:Formula Used For:
Approval ProcessesDefine the criteria a record must meet to enter the approval process.
Approval StepsDefine the criteria a record must meet to enter the approval step.
Assignment Rules for Leads and CasesDefine the criteria the lead or case must meet for it to be assigned.
Auto-Response Rules for Leads and CasesDefine the criteria a lead or case must meet to trigger an auto-response rule.
Case Escalation RulesSpecify criteria a case must meet for it to be escalated.
Custom Buttons and LinksDefine the content for custom links and buttons.
Custom FieldsCreate custom formula fields that automatically calculate a value based on other values, merge fields, or expressions. Users can view formula fields on record detail pages but can’t see the underlying algorithm or edit the value of a formula field.
Custom Summary Formulas in ReportsAutomatically calculate more totals based on existing report summaries using the values, merge fields, or expressions you specify. Users can’t change these totals.
Data ValidationsVerify that the data a user enters in a record meets the standards you specify before the user can save the record. A validation rule can include a formula such as CloseDate >= TODAY().
Default Field ValuesApply a value to a custom field when a user creates a record. Use formulas to define a default value such as TODAY() + 7.Users can change a default value. Default field values can be based on a formula using values, merge fields, or expressions you specify.
Escalation RulesDefine the criteria that a case must meet to be escalated.
Formula FieldsAutomatically calculate the value of a custom field using the values, merge fields, or expressions you specify. Users can’t change the value of a formula field.
ReportsCreate custom summary formulas in your reports to calculate more totals based on the existing summaries in that report.
Validation RulesPrevent users from entering an invalid value in a standard or custom field. Validation rules can be based on formulas and display an error message to users when the value they enter is not valid.
Workflow Field UpdatesAutomatically change the value of a field to a value you specify. The formula can include other values, merge fields, or expressions. You can set field updates to occur as a result of a workflow rule or an approval process.
Workflow RulesDefine the criteria a record must meet to trigger a workflow rule.
Visualforce PagesDefine the content for Visualforce pages.

5. Additional Resources

6. Recommended Articles

Share this article...

Please Leave a Comment

error: Content is protected !!