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

Overcome access dilemmas with permission sets

Use Permission Sets To Overcome Common Access Dilemmas

As an Awesome Admin, it’s probably in your nature to look for any way to optimize a process or situation! As part of that never-ending desire for optimization, I would bet that you’ve spent a lot of time thinking about your permissions setup in Salesforce. Salesforce provides multiple ways to grant permissions to users, each […]

READ MORE
Advance Your Admin Career With Dev Fundamentals

Advance Your Admin Career With Dev Fundamentals

Ready to take the next step in your admin career but unsure where to start? Take a page out of my book and learn development fundamentals to jumpstart your abilities as an advanced admin and extend your Salesforce Platform knowledge. Several years ago, I was at a career tipping point. I felt solid in my […]

READ MORE