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?
Objectives:
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.
Before-Save |
After-Save |
||
Configure to Trigger when a record is created or updated |
Configure to Trigger when a record is deleted |
||
Create Record | ✅ | ✅ | |
Get Record | ✅ | ✅ | ✅ |
Update Record | ✅ (Update Triggering Record) | ✅ | ✅ |
Delete Record | ✅ | ✅ | |
Assignment | ✅ | ✅ | ✅ |
Decision | ✅ | ✅ | ✅ |
Loop | ✅ | ✅ | ✅ |
Collection Sort | ✅ | ✅ | ✅ |
Collection Filter | ✅ | ✅ | ✅ |
Action | ✅ | ✅ | |
Subflow | ✅ | ✅ | |
Scheduled Path |
✅ | ||
Asynchronously Path |
✅ | ||
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!
Formative Assessment:
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.
Hi Rakesh,
Thanks for the informative content you produced, appreciated,
Can I get the answer for your assessment just to undestand if i did it right?
Thanks
JIACHANG
Another great article. Question – let’s say you are converting a workflow rule to flow. The rule has two actions associated: one is to do a same-record field update, and the other is to send an email alert. The first action could be converted to a before-save flow, but the second would need an after-save flow. Would the best practice be to separate these actions into two flows? They would have the same conditional logic, so for maintenance, it would be simpler to just place them both into the after-save flow. But we could probably reduce some processing time by moving the same-record update to the before-save flow. I suppose this would depend on one’s overall environment and administrative bandwidth, but curious what your approach would be.
Awesome to hear! Glad you are finding the tips helpful.
I strongly recommend using Before-save for same-record fields update, whereas After-save sends out an email alert.
Thank you for this information and taking the time to explain the options of record-triggered flows. I have a challenge before me. I have a screen flow that is triggered from a button. In this flow I create a record. The challenge I am having is trying to use the information from this newly created record to then make an API call that will generate a URL string and I want to save this URL string on that newly created record. All avenues have given me the “You have uncommitted work pending.” error. Can this be done with flows?
This can be done via Flow and I have implemented similar scenario in my previous project. Can you please email me more details? Thank you!
Hi Rakesh, I have emailed you using the form.
Great post! very useful, thanks a lot!
I was wondering, if I created a Flow that triggers when a record is created or updated, BUT, I need to run it for existing records too, would it be possible to accomplish this with a “Scheduled Flow”? Or do I always need to kind of “update” the records to make my flow run?
I am glad this was useful! You have two options:
1. Use Data Loader to update existing records
2. Use One-time Schedule Flow to update existing records
Thanks Rakesh! I believe just selecting “Update” in DataLoader, but not doing “real” changes on the records, will make the flow trigger.
But I am concerned about the amount of records, I may have more than 50000
In such cases set the batch size to 100 in the Data Loader.
Will do so, thanks a lot!