Use IsNew(), IsChanged() and PriorValue() in Flow Formulas : jenwlee

Use IsNew(), IsChanged() and PriorValue() in Flow Formulas
by: jenwlee
blow post content copied from  Jenwlee's Salesforce Blog
click here to view original post


Excited

A very much awaited feature is coming in Summer ’21 – we will have the ability to use the IsNew(), IsChanged() and PriorValue() syntax in formulas as you can in workflow rules and processes in record-triggered and scheduled flows.

Here are a few lessons learned from implementing this use case:

  • Use the IsNew(), IsChanged() and PriorValue() syntax in flow formulas 

Business Use Case:  Addison Dogster is the system administrator at Universal Containers. She has 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.

Solution: In Winter ’21 release orgs, Addison would have to create the solution using a process (older automation feature). With Summer ’21, she is able to create this automation in flow (end state declarative automation tool). YES! 

The automation solution (in this case, a record-trigger flow) looks like this:

FormulaExampleFlow

(1) We have this record-triggered flow start 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 case record. 

Highlighted Steps: 

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

1. Create the record-triggered flow shown above. In Lightning Experience, it is found under Process Automation | Flows. Click on “New Flow.” Select Record-Triggered Flow. For those using Salesforce Classic, flow can be found in Create | Workflows & Approvals | Flows. Select the Record-Triggered Flow and click the Create button.

In the flow, we would configure the following flow resources.

A. We need to create 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 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.

This is 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”)

NeworWorkingCaseFormula

B. We need to create a formula resource called PriorValueNeworWorkingCriteriaFormula to determine whether the case record is changed and the status’ prior value 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.

This is 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” )

PriorValueNeworWorkingCriteriaFormula

C. First, configure the start element as follows.

  • Trigger: A record is created or updated
  • Run Flow: Before the record is saved
  • Object: Case (no conditions are configured) 

 

FormulaExampleFlow-Start

D. Create a Decision flow 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

FormulaExampleFlow-Decision

E. Create an Assignment element for each outcome to update the field values according to your use case.

F. Debug the flow to ensure it is working as expected.

G. Save and activate your flow. 

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


May 26, 2021 at 05:30PM
Click here for more details...

=============================
The original post is available in Jenwlee's Salesforce Blog by jenwlee
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.
============================