Getting Started with Salesforce Flow – Part 35 (When to Use Before-Save vs After-Save Record-Triggered Flows)

Getting Started with Salesforce Flow – Part 35 (When to Use Before-Save vs After-Save Record-Triggered Flows)

Last Updated on June 6, 2021 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:

  1. Update fields on new or changed records – means that you want to update the fields on record that started the Flow
  2. 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: 

  1. Create or update related records.
  2. 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. 
    1. For example, sending Email alerts. 
  3. Perform actions other than updating the record that launches the Flow. 

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!

  1. 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). 
  2. 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’. 
  3. 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. 
  4. 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. 
  5. 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.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

13 thoughts on “Getting Started with Salesforce Flow – Part 35 (When to Use Before-Save vs After-Save Record-Triggered Flows)

  1. 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?

  2. 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?

      1. 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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.