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

Flow Enhancements Summer '24.

Flow Enhancements | Summer ’24 Be Release Ready

Summer ’24 is almost here! Learn more about new Flow Builder enhancements like the Automation App, Action Button (beta), and more, and check out Be Release Ready to discover more resources to help you prepare for Summer ’24.  Want to see these enhancements in action? Salesforce product manager Sam Reynard and I will demo some […]

READ MORE
A Salesforce Admin's Guide to TrailblazerDX 2024.

A Salesforce Admin’s Guide to TrailblazerDX 2024

The Trailblazer community is coming back together on March 6-7, 2024, in San Francisco and on Salesforce+ for TrailblazerDX 2024—join us! Generative artificial intelligence (AI) is revolutionizing application development, creating the most significant shift and opportunities for both admins and developers in decades. At TDX, you’ll learn to supercharge user productivity, automate business processes, and […]

READ MORE
Be Release Ready Spring '24 | The Ultimate Guide to Prompt Builder.

The Ultimate Guide to Prompt Builder | Spring ’24

Artificial intelligence (AI) is not a new concept to Salesforce or to Salesforce Admins. Over the years, Salesforce has empowered admins with a user-friendly interface for the setup and configuration of predictive AI features such as Opportunity Scoring, Lead Scoring, Einstein Bots, and more. The introduction of generative AI in Salesforce brings even more possibilities […]

READ MORE