Before Save Assignment VS Update Records Performance Benchmark : Luke Freeland

Before Save Assignment VS Update Records Performance Benchmark
by: Luke Freeland
blow post content copied from  Blog
click here to view original post

Salesforce recently updated Flows so that before-save flows can now have “Update Records” as an option to update fields on an inserted or updated record before it’s saved to the database. Originally, one had to do it through the Assignment element but now either is an option. Let’s benchmark each and see if one performs better than the other.

Averages After 10 Runs

Before-Save Assignment Before-Save Update Records
61.1 milliseconds 64.8 milliseconds

See Record Automation Benchmarking for additional timings of the different same-record update options.


For each solution, a custom object was created with an Auto Number name field and with a custom text field. 200 records are inserted in each solution’s custom object using apex from Execute Anonymous using VS Code and each solution sets the custom text field to the same value. Immediately before and after the insert statement Limits.getCPUTime is invoked. The start time in milliseconds is subtracted from the end time to determine the overall insertion time. These results are then recorded in a Benchmark Result custom object.

A before-save flow was created on each of these two objects. One flow uses the “Assignment” element to update the “Text 1” field to “Benchmark Test”. The other before-save flow does the same thing but with an “Update Records” element.

System.debug was avoided because turning on system.debug usually causes everything to be slower. Dan Appleman and Robert Watson shared that in their Dark Art of CPU Benchmarking presentation. Parsing each debug log after each benchmark run is also tedious.

The timings shown include the general overhead of inserting 200 records. As a result, the timings shouldn’t be interpreted as each operation takes X time. Each one is X plus Y overhead.


After 10 runs each, the Assignment element averaged 61.1 milliseconds versus the Update Records’ 64.8 milliseconds. This indicates that their runtime performance is approximately equal. It’s unclear why Salesforce added another element to Before-Save flows that essentially does the same thing. My guess is to reveal the intent of the flow at first glance in the canvas without knowing that Assignments do the same thing.

Update Records also let’s one specify the criteria under which the records should be updated, which the Assignment operator doesn’t have. One would have to use a decision element first so that’s nice that it saves a step but my preference is to have the decision element so that one can see it’s being “filtered” and updated only if some criteria is met. Update Records is also slightly faster at defining the field definitions because the fields are shown immediately whereas one has to choose $Record and then the field in an assignment.

I don’t have a strong preference over using one over the other as long as the same way of doing it is used consistently throughout the org. It would be nice if there’s just one way of doing it so builders don’t have to constantly answer the question “Which should I use and why?”. If you have a compelling reason to use one over the other, let me know in the comments!

Before-Save Update Assignment Element Definition
Before-Save Update Records Element Definition

Before-Save Assignment Timings

Run # Time in Milliseconds
1 58
2 69
3 58
4 70
5 59
6 70
7 71
8 59
9 58
10 55

Average: 61.1 milliseconds

Before-Save Update Records Timings

Run # Time in Milliseconds
1 64
2 56
3 72
4 67
5 66
6 55
7 53
8 77
9 64
10 74

Average: 64.8 milliseconds

July 03, 2021 at 12:14AM
Click here for more details...

The original post is available in Blog by Luke Freeland
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.