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

AI for Admins: What You Need to Know to Make Einstein Bots a Success

Einstein Bots interact with your customers quickly and accurately with automation and artificial intelligence (AI) capability. In terms of AI initiatives, the biggest challenge is measuring business impact. One reason most AI projects fail is that people are looking at “model performance” instead of business value, such as how much money, in either additional revenue […]

READ MORE
Mountains and greenery next to text that says, "Share User Feedback in Slack with OmniScripts."

Seamlessly Share User Feedback in Slack with OmniScripts

⚠️ The challenge As #AwesomeAdmins, we’re used to managing our Salesforce orgs and constantly making our best efforts to turn user feedback into actionable enhancements together with the development team. Now let’s imagine it’s the go-live day of a brand new, industry-specific component. We’re all so excited about it and we want to enrich it […]

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