Greenery next to text that says," Three Powerful Formula Functions You Can Use in Flow"

Three Powerful Formula Functions You Can Use in Flow

By

Often times in automation, you want activities to occur only when the record is new, when the record is updated, or when there was a record update but only if the previous field value was ‘x’. The power formula functions IsNew(), IsChanged(), and PriorValue() that you use in workflow rules and processes can also be used in record-triggered flows.

For those new to these formula functions, let’s get oriented.

  • The formula function IsNew() checks to see if the record is new and will return ‘true’ if it is. The function will return ‘false’ if the record already exists.
  • The formula function IsChanged(field) compares the values of a field to its previous value and returns ‘true’ if the values are different. If the values are the same, the function returns ‘false’.
  • The formula function PriorValue(field) returns the previous value of the field.

The business problem

Addison Dogster is the system administrator at Hello Mochi. She’s been tasked with creating automation for case management that requires determining when a record is new, a field is changed, and the prior value was a certain value.

The solution

Addison creates an automation solution using a record-triggered flow, which is illustrated below.

(1) The record-triggered flow starts when a new case record is created or a case record is updated before the record is saved. (2) We determine whether the case record is (a) new or the status is ‘Working’ or (b) the status is changed and the status was previously ‘Working’. (3) Lastly, updates are made to the same case record that fired the process.

Configured record-triggered flow using flow formulas

Note: This flow is an example that shows the use of the IsNew(), IsChanged(), and PriorValue() formula functions in Flow formulas. This is not meant to be a fully documented solution.

Let’s see how Addison creates her record-triggered flow.

First, she’ll configure the following flow formula resources for use in the Decision element later on.

She creates a formula resource called “NewOrWorkingCaseFormula” to determine whether the case record is new and the status is ‘New’ or the case record is changed and the status is ‘Working’. If this evaluates to true, then the flow resource is set to true.

Best practice tip: Provide a description so you and other/future admins know what this flow resource is used for.

Here’s how that flow resource would be configured.

  • Resource Type: Formula
  • API Name: NewOrWorkingCaseFormula
  • Data Type: Boolean
  • Formula: (ISNEW() && TEXT({!$Record.Status}) = “New”) ||
    (ISCHANGED({!$Record.Status}) && TEXT({!$Record.Status}) = “Working”)

Note: When you copy and paste the formula into Flow Builder, replace the curly quotes with straight quotes. Otherwise, your formula syntax will be invalid when you check the syntax.

Configured NewOrWorkingCaseFormula formula resource

Next, Addison creates a formula resource called “PriorValueNeworWorkingCriteriaFormula” to determine whether the case record is changed and the prior value of the status is ‘New’ or ‘Working’. If this evaluates to true, then the resource is set to true.

Best practice tip: Provide a description so you and other/future admins know what this flow resource is used for.

Here’s how that flow resource would be configured.

  • Resource Type: Formula
  • API Name: PriorValueNeworWorkingCriteriaFormula
  • Data Type: Boolean
  • Formula: ISCHANGED({!$Record.Status}) &&
    (TEXT(PRIORVALUE({!$Record.Status})) = “New” || TEXT(PRIORVALUE({!$Record.Status})) = “Working” )

Note: When you copy and paste the formula into Flow Builder, replace the curly quotes with straight quotes. Otherwise, your formula syntax will be invalid when you check the syntax.

Configured PriorValueNeworWorkingCriteriaFormula formula resource

Next, Addison configures the Start element as follows.

  • Object: Case
  • Trigger: A record is created or updated
  • Conditions: 1
  • Optimize for: Fast Field Updates (Note: This means we’re only taking action on the record that fires the process. This option also gives us better performance.)

Configured Start element for the record-triggered flow

Where possible, Addison wants to minimize the number of records that go through this process, so she sets an entry condition using a formula to match both situations: (a) new or the status is ‘Working’ or (b) the status is changed and the status was previously ‘Working’.

Formula: (ISNEW() && TEXT({!$Record.Status})=”New”) ||
(ISCHANGED({!$Record.Status}) && TEXT({!$Record.Status}) =“Working”)

Note: When you copy and paste the formula into Flow, replace the curly quotes with straight quotes. Otherwise, your formula syntax will be invalid when you check the syntax.

Configured Start element for the record-triggered flow

Addison creates a Decision element that determines which path to take: (a) NewOrWorkingCase-Criteria or (b) PriorValue.

Best practice tip: Provide a description so you and other/future admins know what this flow resource is used for.

Configure as follows:

  • Outcome: NewOrWorkingCase-Criteria
    • {!NewOrWorkingCaseFormula} Equals {!$GlobalConstant.True}
    • When to Execute Outcome: If the condition requirements are met
  • Outcome: PriorValue:
    • {!PriorValueNewOrWorkingCriteriaFormula} Equals {!$GlobalConstant.True}
    • When to Execute Outcome: If the condition requirements are met

Configured Decision element showing the use of the two formula resources as outcomes

Addison then creates an Assignment element for each outcome to update the field values of the case record according to the use case. Because Addison is using a fast field update, she doesn’t need the Update Records flow element to update her case record. The Assignment element pulls double duty and takes care of the update for her. How efficient!

Addison is an #AwesomeAdmin, so she tests her flow to ensure it works as expected by using the Debug feature.

Once Addison confirms all is working as expected, she saves and activates her flow.

Now it’s your turn! Take these three formulas for a whirl in Flow, and share your use cases with us on Twitter @SalesforceAdmns.

Resources

Einstein next to text that says, "Be an AI-Minded Salesforce Admin."

Be an AI-Minded Salesforce Admin

Understanding the fundamentals of artificial intelligence (AI) is critical to being an #AwesomeAdmin. This technology has opened up broadly and both people and businesses are finding new and inventive ways to weave it into products and our lives. There’s no better time to get up to speed on AI and how you will be able […]

READ MORE
The admin Learn Moar Trailhead Community badge next to text that says, "#2 Reactive Screen Components (Beta)."

Reactive Screen Components (Beta) | Learn MOAR Summer ’23

In Summer ’23, admins can start taking advantage of reactivity with reactive formulas. Read this blog post to learn why reactive screens will transform the screen-building game for Flow and for the Salesforce platform as a whole. Then complete the Learn MOAR Summer ’23 for Admins trailmix to earn a special community badge. Before we […]

READ MORE
""

How #AwesomeAdmins Help Salesblazers Sell as a Team

Selling has become a team sport, with 81% of reps saying team selling helps them close deals. For Salesforce Admins, enabling a team selling approach can create both opportunity and some complexity. Team selling weaves in many of the core responsibilities admins practice each and every day, such as permission sets, security, and data management. […]

READ MORE

Have an Idea for a Story?

We are all about the community and sharing ideas.
Do you have an interesting idea or useful tip that you want to share?

SHARE YOUR IDEA