Avoid This Common Salesforce Flow Mistake: Stop Using "Get Records" in a Loop

Salesforce Flow is a powerful tool that allows you to automate business processes, but there's one mistake that even experienced admins make—placing a "Get Records" element inside a loop. This seemingly minor error can cause significant performance issues, like slower flow execution, hitting governor limits, or even causing your flow to fail.

In my latest video, I explain why this happens and show you exactly how to fix it:

👉 Watch the video here: Watch Now

 

Why is Using "Get Records" in a Loop a Problem?

Here’s a visual example of how a common mistake happens in Salesforce Flow:

 

 

 

When building flows that handle multiple records, it’s tempting to place a "Get Records" element inside a loop. However, this can create a performance bottleneck. Here’s why:

  1. Excessive SOQL Queries: Each time the loop runs, the "Get Records" element triggers a new SOQL query. This can quickly add up, consuming Salesforce governor limits—which currently allow only 100 queries per transaction.
  2. Slower Flow Performance: Multiple queries mean slower execution. What should take seconds could take minutes or more, frustrating users relying on the flow for quick results.
  3. Risk of Flow Failure: Hitting governor limits can cause your flow to fail entirely, disrupting critical business processes.

 

How to Fix It: Move "Get Records" Outside the Loop

Luckily, the fix is straightforward. Instead of fetching records in every loop iteration, you can retrieve all records before the loop starts.

Here’s a comparison between the wrong approach and the correct approach:

 

 

 

Steps to Fix the Flow:

  1. Retrieve Records Once: Use "Get Records" before the loop starts and store the results in a collection variable.
  2. Loop Through the Collection: Instead of calling "Get Records" during each iteration, use the records stored in the collection and process them within the loop.
  3. Efficient Processing: This method ensures faster flow performance, stays within limits, and avoids failures.

👉 Want a detailed walkthrough? Watch the full video here: Watch the Video

 

Why This Matters: Benefits of Optimizing Your Flow

By making this small adjustment, you’ll see immediate benefits in your flows:

  • Avoid Hitting Governor Limits: Reduce the number of SOQL queries and stay within Salesforce limits.
  • Improve Flow Performance: Your flows will execute faster, enhancing the user experience.
  • Scalable Automation: As your data set grows, your flows will be better equipped to handle large volumes without slowing down or failing.

 

Real-World Example:

Let’s say you have a flow that processes Opportunities. You want to loop through each Opportunity and fetch related Contact records. If you place "Get Records" inside the loop, you’ll run a SOQL query for each Opportunity—quickly hitting limits if you have a large data set.

Instead, use "Get Records" outside the loop, store all the relevant Contacts in a collection variable, and reference them inside the loop.

 

Final Thoughts:

If you're building Salesforce Flows, it’s crucial to avoid placing "Get Records" inside loops. By following best practices, you can create efficient, scalable flows that avoid performance issues and governor limits.

👉 Watch my video for the full tutorial on how to fix this mistake:
Watch Now