Last Updated on February 5, 2025 by Rakesh Gupta
Big Idea or Enduring Question:
-
How can I limit the number of records returned by the Get Records element in Salesforce Flow?
Objectives:
After reading this blog, you’ll be able to:
- Learn how to limit the number of records returned by the Get Records element.
- Avoid Flow errors by applying filters for efficient data retrieval.
- Optimize Flows to stay within Salesforce governor limits.
- And much more!
Business Use case
Olivia Bennett, a Junior Developer at Gurukul on Cloud (GoC), was exploring the Salesforce Spring ’25 release notes when she came across a new feature that allows developers to control the number of records retrieved with the Get Records element.
Her mentor, Harper Davis, introduced a simple use case to demonstrate how to use this new feature effectively:
Retrieve the 2000 most recently created leads where the Email field is populated.
What Is the Get Records Element?
Salesforce stores data in objects. Some objects are available in Flow as part of global variables. For example, User, UserRole, and Profile are system-provided variables that can be referenced throughout the Flow without requiring a query.
For other objects, such as Account or Lead, the records must be fetched from their respective tables. This is where the Get Records element comes into play, allowing you to retrieve data from the respective object. For instance, you can use the Get Records element to fetch all active Campaigns.
The Get Records element is more or less equivalent to List Views, as it enables you to filter and fetch specific records based on defined criteria.
Why Is Setting the Number of Records to Store Important?
One of the most common governor limits users encounter when using the Get Records element is the Too many query rows: 50001 error. This error occurs when the query retrieves more than 50,000 records, exceeding Salesforce’s governor limits, and results in a runtime error. This issue is especially prevalent when working with large datasets and attempting to fetch all records without proper filtering.
When dealing with large data volumes (LDV), using the Get Records element without constraints can lead to performance issues or exceed Salesforce governor limits. To avoid such errors and optimize Flow performance, now after spring’25 release you can set an upper limit on the number of records retrieved. By using the All records, up to a specified limit option, you can control the maximum number of records fetched, ensuring the Flow runs efficiently and stays within the limits.
Automation Champion Approach (I-do):
Proof of Concept
I used the debug log to verify whether the above flow is working correctly. The flow is returning 9 records, which matches my expectations. I am running this in a developer org.
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? Feel free to share in the comments below.




what about the other data which is not fetched by the first query. For example you have overall 10k records and want to get them in 5 queries with each 2k records. Is this possible?
I don’t need all the data, which is why I set the limit to 2K. Currently, there is no clean way to fetch the data the way you want without inserting some workaround in between.
Thank you so much for your clear and concise explanation of how to limit the number of records returned by the Get Records element in Salesforce Flow.
This will definitely help me optimize flows and improve performance within our organization. I appreciate you taking the time to share this valuable information.
Thanks for reading 😊