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 !
Best Answer
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 beforeId
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:
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):The "Start Date Changed?" Decision element checks whether the
ExistingEmployee.Start_Date__c
field value equals the$Record.Start_Date__c
field value: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.