Since Spring’20 release there is a new before save record-triggered flow option which sounds very fancy. The release note is one of the cutest I have ever read (it says “Update 10 Times Faster!!”), yet a difficult one to understand. Thus today we will translate that into super easy English!
The Concept Of Before-Save
There are many technical details regarding before-save trigger, but to me the most important part is to know the following:
After some record changes trigger the flow, you can update other fields of the record IN ONE SAVE.
Example: When Account Annual Revenue changes to a high number, I want to update the Account Rating to Hot. If I use before-save, I can execute all these actions at once. (The record is only saved one time)
After some record changes trigger the flow, the system saves the changes first, and then you can update other fields or records in a second save.
Example: When Account Annual Revenue changes to a high number, I want to update the Account Rating to Hot. If I use after-save, the record is saved once when annual revenue changes and saved for the second time when the rating is updated to Hot.
Simply by knowing that after-save will execute at least one more saving, it is easy to understand why before-save is faster.
How Much Faster Exactly Is Before-Save?
Is it really 10 times? Well I found this brilliant blog who actually did the testing. It’s hard to say how Salesforce calculated 10 times, but at least we do know before-save trigger does run faster. A side note, do pay attention to the order of execution if you are working on your admin certificate 😉
If Before-Save Is So Amazing, Why Do We Need After-Save
The examples I provided above are silly. They are only for showing the difference between before and after-save for the same case, but it is really clear that before-save is the best option for that scenario. Then you might wonder why do we still need after-save. In fact, there are several actions that can only be achieved through the after-save trigger. Here is the official explanation from the release note:
- Access field values that are set only after the record is saved, such as the Last Modified Date field or the ID of the new record.
- Create or update related records.
- Perform actions other than updating the record that launches the flow.
In short, the before-save trigger can only UPDATE the ORIGINAL RECORD that triggers the flow. If you want to do any other actions, you have to use the after-save trigger instead.
Cheatsheet: How To Decide When To Use Before-Save
I have prepared a simple cheatsheet for you to help you decide whether you should use before-save trigger:
Working On A Tricky Problem?
Not only does the before-save trigger run faster, but it also solves many problems in a super effective way. Just this month alone I had two people telling me the use cases of before-save triggers that either break Salesforce’s limitation or speed up the process enormously. Literally life-saving! Thus my sincere advice – always think about if a before-save trigger can solve the tricky problems before you jump into a complex solution.
Time For An Example!
Want to use a formula as the criteria in your duplicate rule? A before-save trigger can achieve that!