Request a Call Back

How do I handle DML statements in loops within a complex Salesforce Flow?


I’m building a Flow to update related Opportunity Line Items when an Account is updated, but I keep hitting the "Too many DML statements: 151" governor limit. I know the golden rule is "Never put a Pink element in a Loop," but I’m struggling to properly bulkify my logic. Can someone walk me through the correct way to use a Collection Variable and the "Assignment" element to stage these updates so I only use one "Update Records" call at the end?


   2025-02-20 in Business Analysis by Christopher Vance | 18914 Views


All answers to this question.


This is a classic "Admin to Developer" hurdle. Inside your loop, you should only use an Assignment element. First, create a single Record Variable (e.g., var_SingleOLI) and a Record Collection Variable (e.g., col_OLIsToUpdate). Inside the loop: 1. Assign the new values to var_SingleOLI. 2. Use a second Assignment element to "Add" var_SingleOLI to col_OLIsToUpdate. 3. After the loop finishes (the "default" path), place one single Update Records element and point it to the entire col_OLIsToUpdate collection. This consumes only 1 DML statement regardless of whether you are updating 5 or 500 records, which is the key to scalable Flow design.

   Answered 2025-04-15 by Stephanie Woods


Are you also checking for null values or empty collections before that final Update element to prevent the Flow from crashing when no records meet the criteria?

   Answered 2025-05-02 by Brandon Lee

  • Brandon, I actually wasn't doing that, and it's a great point. I’ve added a Decision element right after the loop to check if col_OLIsToUpdate is "Is Null: False." This has already saved me from several "unhandled fault" emails today. It’s funny how these small "defensive programming" steps make the whole system feel so much more professional and robust for the end-users.

       Commented 2025-05-08 by Christopher Vance


Always use the "Debug" button in Flow Builder with the "Rollback" option enabled so you can test your bulk logic without actually messing up your sandbox data.

   Answered 2025-06-20 by Amanda Scott

  • Good advice, Amanda. The new 'Expandable Debug' view in the Summer '24 release makes it even easier to track how those collection variables are growing in real-time.

       Commented 2025-06-25 by Stephanie Woods



Write a Comment

Your email address will not be published. Required fields are marked (*)




Suggested Questions

Introduction to Project Management..
Posted 2026-07-07 by learnersera.
Balancing Link Metrics With Structural Entity Maps..
Posted 2025-05-12 by learnersera.
Balancing Link Metrics With Structural Entity Maps..
Posted 2025-05-12 by learnersera.
Impact of Entity Authority on Organic Competitive..
Posted 2025-01-04 by learnersera.
Backlinks vs Entity Authority for SEO Rankings..
Posted 2025-04-14 by learnersera.
How are modern agile organizations evaluating scrum..
Posted 2025-07-19 by learnersera.
Is a specialized technical degree required to..
Posted 2025-10-05 by learnersera.
How heavily do hiring managers weigh professional..
Posted 2025-09-12 by learnersera.

Disclaimer

  • "PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc.
  • "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA.
  • COBIT® is a trademark of ISACA® registered in the United States and other countries.
  • CBAP® and IIBA® are registered trademarks of International Institute of Business Analysis™.

We Accept

We Accept

Follow Us

 facebook icon
 twitter
linkedin

Instagram
twitter
Youtube

Quick Enquiry Form

WhatsApp Us  /      +1 (713)-287-1187