Last Updated on April 28, 2022 by Rakesh Gupta
Big Idea or Enduring Question:
When to use “Before-Save” vs “After-Save” Record-Triggered Flows?
After reading this blog post, you will be able to understand:
- When should you use Before-save record-triggered flow?
- When should you use After-save record-triggered flow?
Business Use Case
Sergio Armendariz is an App Developer at Gurukul on Cloud (GoC). After attending the local user group meeting, he was excited to explore the newly introduced record-triggered Flow. However, Sergio does not have a Developer’s background. So, it is a bit difficult for him to understand when to use Before-save vs. After-save record-triggered Flow.
Undaunted, he tapped GoC’s Solution Architect, Rakesh Gupta, to get to the bottom of this!
Automation Champion Approach (I-do):
Rakesh and Sergio set up a Zoom meeting to discuss the difference between Before-save vs. After-save record-triggered Flow and when to use what?
The Before-save Flow is a trigger that is performed before an operation – such as an insert, update, delete, etc. You can use such a Flow to check or change values before data is updated or inserted in the database. A Before-save is much faster because each record does not get saved to the database again. Avoiding that extra save procedure means skipping another round of Assignment rules, Auto-response rules, Workflow rules, and other customizations that take time to execute.
The After-save Flow trigger, on the other hand, is executed after an operation – such as an insert, update, etc. You can use such a Flow to update data in related objects or send an email alert. An After-save can help you to accomplish the same goal as a Process Builder (remember Process Builder is an After-save trigger).
Use a Before-save Flow on the following use cases:
- Update fields on new or changed records – means that you want to update the fields on record that started the Flow
- Trigger a Validation rule (this is a custom solution not available out-of-the-box)
Use an After-save Flow on the following use cases:
- Create or update related records.
- Access fields like the Last Modified Date field or the new Record’s ID. Notice that these fields populate only after a record is saved.
- For example, sending Email alerts.
- Perform actions other than updating the record that launches the Flow.
Record-Triggered Flow Features
Here’s the breakdown of all the features and actions that are supported in before vs after save record-triggered flow.
|Configure to Trigger when a record is created or updated
||Configure to Trigger when a record is deleted
|Update Record||✅ (Update Triggering Record)||✅||✅|
|Trigger on Create
|Trigger on Update||✅||✅|
|Trigger on Delete
Hands-on Excercise (You-do):
As Rakesh is done explaining when to use Before-save vs. After-save record-triggered Flow to Sergio, he wants to validate Sergio’s understanding. So, Rakesh assigns a few hands-on exercises to Sergio. Please help Sergio with the following exercises and, while at it, also master the concepts!
- Steven Greene is working as a System Administrator at Universal Containers (UC). He received the following requirement from his Manager – whenever an Account is created or updated, auto-populate the number of open opportunities counts in a custom field on the Account i.e. No. of Open Opportunities (No_of_Open_Opportunities__c).
- Steven Greene is working as a System Administrator at Universal Containers (UC). He received the following requirement from the management – whenever an Account’s custom field, ‘Out of Business’ (out_of_business__c) is checked, update the related open Opportunity Stage to ‘Closed-Lost’.
- Steven Greene is working as a System Administrator at Universal Containers (UC). He received the following requirement from the management – when an Opportunity Stage is updated to Closed-Won, send an Email Alert to the Account owner.
- Steven Greene is working as a System Administrator at Universal Containers (UC). He received the following requirement from the management – when a Lead is created without Phone or Email, auto-create a Task for the Lead owner to update the Contact Information on the Lead.
- Steven Greene is working as a System Administrator at Universal Containers (UC). He received the following requirement from the management – when a Lead is created with Annual Revenue greater than $ 5M, update the Rating to Hot.
Good Luck with these exercises!! Do not fret if you get stuck – know that I am just an email away!
I want to hear from you!
What is one thing you learned from this post? How do you envision applying this new knowledge in the real world?
Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.