Record triggered flow can be considered the most common flow type in Salesforce. It is the only flow type that automatically runs when a record is created, updated, or deleted. Depending on what you want to perform, you can choose to run the flow before or after the record is saved. If you go for "Fast Field Updates", it runs before save, while "Actions and Related Records" runs after save. If you just need to update fields on the record that triggers the flow, before save is the right option. Although you can update only the triggering record, it is crucial to use before save instead of after save. Because before save flow runs 10 times faster than the after save flow! Moreover, it doesn't consume any DML limits.
There are 2 ways to update the triggering record in before save record triggered flow.
Using the Assignment Element to Update the Triggering Record
The concept of "before save" implies that changes occur prior to the record being saved to the database. As a result, there is no actual update; it simply modifies the field values before saving. This is also the reason why a before save record triggered flow doesn't consume any DML limits.
When Salesforce introduced the before save record triggered flow, Assignment element was the only option to update the triggering record. To update the triggering record, you only need to include an Assignment element and configure the desired field values. No additional Update Records element is required.
For instance, updating the Opportunity record requires just these simple steps.
After a short time, Salesforce added another option to update the triggering record: Update Records element. Let's see how to use the Update Records element in before save record triggered flow.
Using the Update Records Element to Update the Triggering Record
In other types of flows, it is possible to use the Update Records element to update any record in the system. However, Update Records element can update only the triggering record in before save record triggered flow. As you can see, the other options are not available.
We mentioned that the concept of "before save" implies no record update. So, what purpose does the Update Records element serve? In a before save record triggered flow, the Update Records element functions similarly to the Assignment element, meaning it doesn't consume from DML limits either.
Here are the debug logs of this before save record triggered flow with an Update Records element. As you can see, it doesn't consume from DML statements/rows.
Both options update the triggering record, and neither consumes from the DML limits. So, what sets them apart? Which one should you choose?
Differences Between Assignment and Update Records Elements in Before Save Record Triggered Flow
As you can see from the previous examples, there is no big difference between these elements in before save record triggered flow. There is no definitive correct option; you can use either of them to update the triggering record. Now, let's explore the pros and cons of each element.
- You can use the Assignment element to assign values to other variables too. Therefore, it can be hard to see which Assignment element is updating the record and which one is not. Using the Update Records element can improve the visibility and provide a clearer indication for the user.
- If you decide to switch the before save flow to an after save flow, your Assignment elements will no longer update the record. On the other hand, the Update Records element will persist in updating the triggering record. This flexibility enables you to seamlessly transition between record triggered flows that run before or after the record is saved. However, if you built your flow using multiple Update Records elements, you may need to rebuild your flow after switching to after save. This is because it is not a good practice to update the same record multiple times in an after save record triggered flow.
- While both perform the same function, there is a slight difference in their performance. Both execute very quickly, that's for sure. However, based on some tests, the Assignment element runs a little bit faster than the Update Records element.
Here are the results of a 10 round test run for these elements.
Assignment | Update Records | |
---|---|---|
1st Run | 0.25 seconds | 0.25 seconds |
2nd Run | 0.27 seconds | 0.34 seconds |
3rd Run | 0.21 seconds | 0.24 seconds |
4th Run | 0.21 seconds | 0.29 seconds |
5th Run | 0.23 seconds | 0.40 seconds |
6th Run | 0.21 seconds | 0.36 seconds |
7th Run | 0.23 seconds | 0.25 seconds |
8th Run | 0.26 seconds | 0.28 seconds |
9th Run | 0.24 seconds | 0.26 seconds |
10th Run | 0.24 seconds | 0.24 seconds |
Average | 0.24 seconds | 0.29 seconds |
Summary
Both the Assignment and Update Records elements can modify the triggering record in a before save record triggered flow. Furthermore, neither of them consumes from the DML limits. Although they both have some pros and cons, there is no absolute right or wrong approach to updating the triggering record.
Excellent post, i've wondered this a lot before. Thanks for doing the research.
Thank you too!
This was a great explanation. I love these topics that dive into the minutia of these processes