Flow: How To Use “Get Records”
This is the most complex data element, so we will break down each part to illustrate.
1. Sort Order
There are three options – Not Sorted, Ascending, Descending. Ascending is from the smallest number to the biggest (if it is date, then it is the oldest to the latest) and Descending is the opposite. You would only want to sort them if later the order matters, for example you want to take the first X records sorted by date. Otherwise leave it unsorted to speed up the execution.
2. How Many Records to Store
If you are only taking the first smallest number, or the one latest date, this will be an extremely helpful feature combining with the first feature. However if you want to take more than one, you will have to store all records and use other elements to handle this. (Ex. Loop, Decision, etc)
3. How to Store Record Data
This is the most complicated setting, and there are four possible scenarios:
3 – 1. Automatically Store All Fields
The most straight forward option. After you choose this, a variable will be automatically created and you can reference all the fields later in the flow. If you only store the first record (Feature 2), it will be a record (single) variable; if you store all records, it will be a record collection variable.
3 – 2. Choose Fields and Let Salesforce Do the Rest
Similar to the first option, the system will also create the variable automatically for this option. The only difference is that you can choose specific fields to get.
Pros: The flow can run faster
The less fields you get, the less the system has to do. Thus, your flow can run faster.
Cons: Potential error might occur
If later you reference the fields that are not specified here, the flow will break.
(For example, I only got Date and Unit Price in graph 3-2.1. If I want to use the List Price to update another variable as graph 3-2.2, I will hit an error as graph 3-2.3.
3 – 3. Choose Fields and Assign Variables – When Get Only One Record
When choosing “Together in a record variable”, the outcome will be similar to choosing fields and letting Salesforce do the rest. However here you can assign a specific variable to store all the values.
Alternatively you can store each field into a separate variable.
These two options in general will take more time for the system to run, and the use case is rare (Which is why there is (advanced) at the back). It might be that you have the variables set in another Apex script of flow, so you want to manually assign these values to unify the names across different places.
3 – 4. Choose Fields and Assign Variables – When Get All Record
Same as 3-3, here you need to assign a specific collection variable to store all the values.
Scenario | Use Case |
---|---|
Automatically Store All Fields | Need most of the fields; Want to prevent potential errors; Flow is too small so tiny inefficiency can be omitted. |
Choose Fields and Salesforce Do the Rest | Only need 2-3 fields; Flow is huge so performance is vital. |
Choose Fields and Assign Variables | Variables are already set and want to unify the names. |
Hi
Are you sure about 3-1 vs 3-2
Reading this article https://metillium.com/2020/10/how-does-automatically-store-all-fields-option-work/ it seems you should always go for “Automatically Store All Fields”
Implying it’s not working slower and thus 3-2 option would not run your flow Faster.
What do you think?
Hello! Great question and I think my explanation in the video might be better than text. It is true that we should always try to use 3-1, but under some specific scenarios (ex. use Action or pass to subflows), all the fields will be queried. To be honest performance wise I don’t think it will make a HUGE difference, but if you have many fields, 3-2 might be a better option if you have these special cases in the flow.
What is a faster and better approach, using get records or selecting the object and conditions at the start of the flow? what is the difference?