5

I'm using a flow to set a field to a certain value (01, 02, 03) depending on the value of another field on the same record. I initially wanted to do it with process builder but because of the mapping it seems I would need three 'criteria nodes' or a formula field. Furthermore, it seems Salesforce is recommending using flows instead of process builder for before update actions as it is faster.

The problem with Flows is that I found a way to trigger it when the record is new or updated but not when the specific field is changed so it triggers every time the whole record is updated even when the field stay the same.

On Process Builder, you can use isChanged and then call the flow with specific record but that kinds of defeat the point of using flows for before Update.

So is there a possibility to do the same thing directly in flow ?

Thank you for the help !

3 Answers 3

12

Flow Builder's before-save trigger executes before the record is saved to the database. For an existing record, the record that's in the database still has the previous field values, while $Record holds the values that are going to be saved.

This means that you can use Get Records to query the record where Id equals $Record.Id, and then use a Decision to compare the value of the field on the queried record with the value on $Record. If the values are different, then the field has changed.

(You can also determine whether a record is new by checking whether $Record.Id is null, because for new records, the before-save trigger is run before Id is populated.)

Here's an example: this flow runs when an Employee custom object record is created or updated. If it's a new employee, it sets an I9 deadline based on the start date. If it's an existing employee it checks whether the start date changed, and if so, sets a new deadline.

The flow looks like this:

A flow with decision nodes to check for a new employee record or a start date change on an existing employee

The "Existing Employee" Get Records element queries for employee records whose Id equals $Record.Id (I cropped out the name/label/description, so it's just the criteria):

Get Records element: criteria is Id equals $Record.Id, get the first record, automatically store all fields

The "Start Date Changed?" Decision element checks whether the ExistingEmployee.Start_Date__c field value equals the $Record.Start_Date__c field value:

Decision criteria: $Record.Start_Date__c equals ExistingEmployee.Start_Date__c

If the start date has changed, some additional logic and an assignment occurs. Remember that in a before-save flow, any changes made to $Record via an Assignment element will be saved to the database.

2
  • 2
    Excellent explanation, thanks. This comment isn't directed at you at all - more of just a general observation ;), but it seems as though needing to add a "Get Records" node to query / retrieve the original record's values defeats much of the purpose of having a before-save flow in the first place, at least in terms of increasing performance... makes me just want to stick with Apex triggers :) Commented May 19, 2020 at 19:34
  • 2024: for anyone finding their way here $Record_Prior has been available on flows since Spring 2001 so consider jvol's simpler solution below
    – bbfire
    Commented Jan 9 at 15:05
3

Coming Soon: Refer to the Prior Values of the Record That Triggered Your Flow

The new $Record__Prior resource allows a flow to check if a specific field on the updated record changed.

source: https://automationchampion.com/2020/12/12/getting-started-with-lightning-flow-part-33-prior-value-of-a-record-in-record-triggered-flows/

1
  • 2
    While this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – identigral
    Commented Jan 6, 2021 at 0:34
0

This issue was resolved with the addition of the isChanged function (and the option to use a formula) for record-triggered flow filter criteria.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .