Formulas in Flow Triggers

As of Spring '21 sandbox testing:

  • Formulas CAN be used in trigger conditions on before save flow triggers

  • Formulas CAN be used in trigger conditions in after save flow triggers

  • Formulas CAN be used in decisions in before save flow triggers IF the Resource uses the Prior Value (eg {!$Record__Prior.IsActive__c}). But you can NOT use formula values from the newly changed record.

  • Formulas CAN be used in decisions in after save flow triggers

  • Formulas CAN be used as the source value in Assignment Updates in before save flow triggers IF the Value uses the Prior Value (eg {!$Record__Prior.IsActive__c}). But you can NOT use formula values from the newly changed record.

  • Formulas CAN be used as the source value Update records elements in after save flow triggers

Example Formulas

My example object is a Contract object (but a Custom object)

IsActive__c

1 2 OR( ISPICKVAL(Status__c ,"Active"), ISPICKVAL(Status__c,"Re-Contracting"))

IsClient__c

1 2 OR(ISPICKVAL(Account__r.Type,"Client"), Account__r.NumActiveContracts__c > 0)

(NumActiveContracts__c is a DLRS that counts the No. of Active Contracts on the Account).

Flow Examples

Formulas in Trigger Conditions

  • Works for Before or After

  • We can use a formula like IsActive__c to run this Flow only when the Contract is Active.

  • Needs to be tested if it works on a Before-Save Flow when the Contract becomes newly Active.

  • Needs to be tested how it works with only when a record is updated…

  • Needs to be tested to create a record as Active

  • Suggested Naming Contract-BeforeCreateUpdate-IsActive

Formulas in Decisions

 

In Before-Save Flows use $Record__Prior

In After-Save Flows use $Record

Using $Record in Before-Save Flows gives this error

Gotchas:

  • The Before-Save Decision will be false when the record is newly Active as the $Record_Prior is the value from before the record was edited.

  • So in this case, do an After-Save Flow to run only on a Newly Activated record to set the required values on activation, then this flow will run in all other cases.

Assignments

In Before-Save Flows use $Record__Prior

If IsClient__c = true then add the special condition, otherwise blank.

In After-Save Flows use $Record

Using $Record in Before-Save Flows gives this error

Gotchas:

  • The Before-Save Update will NOT be correct if the record is Newly Activated… this will lead to data integrity issues.

  • So in this case, do an After-Save Flow to run only on a Newly Activated record to set the required values on activation, then this flow will run in all other cases.

So, use formulas in Flow Triggers IF you can be sure they are stable formulas and be very careful to test what happens when the formula value changes!

Formula Templates

Not Changed

1 {!$Record.Field__c} = {!$Record__Prior.Field__c}

IsChanged

1 {!$Record.Field__c} <> {!$Record__Prior.Field__c}

IsChanged and Was Blank

1 AND(NOT(ISBLANK({!$Record.Field__c})),ISBLANK({!$Record__Prior.Field__c}))

It seems weird to use IS in Prior context, not WAS.