• WHO WE ARE
  • WHAT WE DO
    • Salesforce
      • Implementations
        • Sales Cloud
        • Service Cloud
        • CPQ
        • Field Service Lightning
        • Field Service for SMEs
      • Developments
        • Salesforce Customization
        • Custom Application Development
        • AppExchange Product Development
      • Migrations
        • Classic to Lightning Migration
        • Other Systems to Salesforce Migration
      • Integrations
    • Data Science
      • BI Solutions
      • AI/ML solutions
      • Agentic AI
  • HOW WE DO
    • Delivery Model
    • Our Works
  • REACH US
    • Contact Us
    • Careers
  • BLOG
    • WHO WE ARE
    • WHAT WE DO
      • Salesforce
        • Implementations
          • Sales Cloud
          • Service Cloud
          • CPQ
          • Field Service Lightning
          • Field Service for SMEs
        • Developments
          • Salesforce Customization
          • Custom Application Development
          • AppExchange Product Development
        • Migrations
          • Classic to Lightning Migration
          • Other Systems to Salesforce Migration
        • Integrations
      • Data Science
        • BI Solutions
        • AI/ML solutions
        • Agentic AI
    • HOW WE DO
      • Delivery Model
      • Our Works
    • REACH US
      • Contact Us
      • Careers
    • BLOG
  • [email protected]
  • (+91) 44-49521562
Merfantz - Salesforce Solutions for SMEs
Merfantz - Salesforce Solutions for SMEs
  • WHO WE ARE
  • WHAT WE DO
    • Salesforce
      • Implementations
        • Sales Cloud
        • Service Cloud
        • CPQ
        • Field Service Lightning
        • Field Service for SMEs
      • Developments
        • Salesforce Customization
        • Custom Application Development
        • AppExchange Product Development
      • Migrations
        • Classic to Lightning Migration
        • Other Systems to Salesforce Migration
      • Integrations
    • Data Science
      • BI Solutions
      • AI/ML solutions
      • Agentic AI
  • HOW WE DO
    • Delivery Model
    • Our Works
  • REACH US
    • Contact Us
    • Careers
  • BLOG

Salesforce Flow Best Practices: Efficient Loops & Governor Limit Solutions

Salesforce Flow Best Practices Efficient Loops & Governor Limit Solutions
  • March 21, 2025
  • Tech Blogger
  • Salesforce
  • 0

While Salesforce Flow is widely used for automation, handling loops efficiently within flows remains a challenge for most admins and developers. Poorly designed loops can cause governor limit violations or lead to CPU timeouts, especially when handling large datasets. In this guide, we will see how to handle loops in Salesforce Flow, avoid governor limits, and maximize performance.

  1. Use Assignment Outside the Loop:

Instead of performing DML operations inside the loop, store all records in a collection and update them at once after the loop finishes.

How to Do It:

  • Create a record collection variable.
  • Use “Assignment” to add records to the collection.
  • Perform the DML operation (Create, Update, Delete) after the loop ends.

 Example:

  • Get all Opportunity records with Stage = “Proposal”.
  • Loop through the records.
  • Assign new values to a collection.
  • Update all records using “Update Records” after the loop.

Why It Works:

  • Reduces SOQL and DML operations → Fewer governor limits.
  • Improves performance → Reduces CPU time.
  1. Use a Formula Instead of Decision Inside the Loop:

Instead of using multiple “Decision” elements inside the loop, create a formula field to simplify the logic.

How to Do It:

  • Create a formula field with IF conditions.
  • Reference the formula field instead of adding multiple decision branches inside the loop

Example:

If a formula field checks if Opportunity Amount > $10,000 → Create a single decision using the formula.

Why It Works:

  • Reduces processing time.
  • Simplifies the logic → Fewer elements to execute.
  1. Use Collection Filters Instead of Complex Looping

Instead of applying logic within the loop, use a collection filter to narrow down the data set before starting the loop.

How to Do It:

  • Use “Filter Collection” before starting the loop.
  • Process only the filtered records

Example:

  • Get all cases created this week.
  • Filter out closed cases before entering the loop.

Why It Works:

  • Reduces loop size.
  • Lowers CPU processing time.
  1. Use “Get Records” Only Once

Instead of querying records multiple times inside the loop, query all records at once and store them in a collection.

How to Do It:

  • Use “Get Records” before the loop.
  • Store results in a collection variable.
  • Reference the collection inside the loop.

Example:

  • Get all Accounts.
  • Store them in a collection.
  • Loop through the collection to update values.

Why It Works:

  • Reduces SOQL queries.
  • Improves flow execution time.

Example: Efficient Loop Handling in a Flow

Scenario:

A company needs to update 5,000 Opportunity records to update the “Stage” field based on the amount and close date.

Challenges:

  • SOQL limit: 50,000 records
  • DML limit: 150 statements
  • CPU timeout: 10 seconds

Solution:

  • Get all Opportunity records using a single “Get Records.”
  • Use a “Collection Filter” to reduce the record count to <2,000
  • Use “Assignment” to store updates in a collection variable.
  • Perform a single “Update Records” action after the loop.
  • If more than 2,000 records → Use a scheduled path for batching.

Why This Works:

  • Only one SOQL query is executed → Stays within limit.
  • One DML statement for multiple records → Stays within limit.
  • Reduced CPU time by handling logic outside the loop
  • Avoids hitting the 2,000 record limit by batching.

Common Pitfalls to Avoid:

  • Placing DML actions directly inside loops à Leads to governor limit violations.
  • Executing multiple “Get Records” inside loops à Causes too many SOQL queries.
  • Lack of batching à Causes CPU timeout or data truncation.
  • Ineffective filter usage à Processes too many records unnecessarily

See how FieldAx can transform your Field Operations.

Try it today! Book Demo

You are one click away from your customized FieldAx Demo!

Author Bio

Tech Blogger
+ Recent Posts
  • Salesforce Apex Development Best Practices and Guidelines
    July 4, 2025
    Salesforce Apex Development Best Practices and Guidelines
  • How to Dynamically Evaluate Formulas in Salesforce Apex
    June 19, 2025
    How to Dynamically Evaluate Formulas in Salesforce Apex
  • Comprehensive Overview of Salesforce Agent-Force Platform
    June 12, 2025
    Comprehensive Overview of Salesforce Agent-Force Platform
  • Salesforce GraphQL Revolutionizing Data Queries in CRM
    June 6, 2025
    Salesforce GraphQL: Revolutionizing Data Queries in CRM
Tags: flowSalesforce
  • Previous Salesforce Agentforce: The Ultimate AI Guide
  • Next Salesforce Spring ’24 Features: Important Flow Updates
Merfantz Technologies is a leading Salesforce consulting firm dedicated to helping small and medium enterprises transform their operations and achieve their goals through the use of the Salesforce platform. Contact us today to learn more about our services and how we can help your business thrive.

Discover More

Terms and Conditions
Privacy Policy
Cancellation & Refund Policy

Contact Info

  • No 96, 2nd Floor, Greeta Tech Park, VSI Industrial Estate, Perungudi, Chennai 600 096, Tamil Nadu, INDIA
  • (+91) 44-49521562
  • [email protected]
  • 9:30 IST - 18:30 IST

Latest Posts

Salesforce Apex Development Best Practices and Guidelines
Salesforce Apex Development Best Practices and Guidelines July 4, 2025
How to Dynamically Evaluate Formulas in Salesforce Apex
How to Dynamically Evaluate Formulas in Salesforce Apex June 19, 2025
Comprehensive Overview of Salesforce Agent-Force Platform
Comprehensive Overview of Salesforce Agent-Force Platform June 12, 2025

Copyright @2023 Merfantz Technologies, All rights reserved