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

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

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

  • What is Isnew () ?
    ISNEW() will check if the formula you create is running when a new record is created and will return TRUE if it is. If the record is being edited, the function returns FALSE.                                                                                                
  • What is ISCHANGED() ?
    Compares the value of a field to the previous value and returns TRUE if the values are different. If the values are the same, this function returns FALSE.                                                                                                                                                         
  •  What is PRIORVALUE() ?
    PRIORVALUE function gets the previous value of a field that is the same value if the record is being created, or the real previous value if the record is being updated.                                                           
  1. Business Use Case:   System administrator in saleforce  org. has been tasked with creating automation for Lead management that requires determining when a record is new, a field is changed and the prior value was a certain value.

Solution: Summer ’21 release orgs, we able to create this automation in flow (end state declarative automation tool)

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

 

(1) We have this record-triggered flow start when a new Lead record is created or a Lead record is updated before the record is saved. (2) We determine whether the Lead record is (a) Working – Contacted or the status is Open – Not Contacted or (b) the status is changed and the status was previously Open – Not Contacted. (3) Lastly, updates are made to the Lead 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 onNew 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 IsChangedLeadStatusFormula to determine whether the Lead record is new and the status is “Working – Contacted” or the Lead record is changed and the status is “Open – Not Contacted.” 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: IsChangedLeadStatusFormula
  • Data Type: Boolean
  • Formula: (ISNEW() && TEXT({!$Record.Status}) = “ Working – Contacted”) ||
    (ISCHANGED({!$Record.Status}) && TEXT({!$Record.Status}) = “Open – Not Contacted”)

B. We need to create a formula resource called PriorValueCriteriaFormula to determine whether the Lead record is changed and the status’ prior value is “Working – Contacted” or “Open – Not Contacted.” 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: PriorValueCriteriaFormula
  • Data Type: Boolean
  • Formula: ISCHANGED({!$Record.Status}) &&
    (TEXT(PRIORVALUE({!$Record.Status})) = “Working – Contacted” || TEXT(PRIORVALUE({!$Record.Status})) = “Open – Not Contacted” )

C. First, configure the start element as follows.

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

D. Create a Decision flow element that determines which path to take: (a) WorkingOrOpen – ContactedLeadCriteria 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: WorkingOrOpen – ContactedLeadCriteria
  • {!IsChangedLeadStatusFormula} Equals {!$GlobalConstant.True}
  • When to Execute Outcome: If the condition requirements are met
  • Outcome: PriorValue:
  • {!PriorValueCriteriaFormula} Equals {!$GlobalConstant.True}
  • When to Execute Outcome: If the condition requirements are met

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

FDebug 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.