[SalesForce] Number of iterations exceeded – Flow Error

I have a flow that loops through Opportunity Line Items. When the number of line items get large it get an error in my flow. The UI gives the following message "You or your organization has exceeded the maximum limit for this feature." But I am also seeing "Number of iterations exceeded" in the debug logs when I run the flow from the designer.

I have not seen any documentation on any iteration limits. I can loop through all of the line items(562) with a simple assign as the only element. But as I add other decision and other elements I get the error. With several elements in the loop I can only process less than 100 items. This is not acceptable for our use case.

Has anyone else seen this same error and limitation? Is there any consistency to it that you can develop around? Or are flow just truly not bulkified?

Best Answer

I have also been running into the 'Number of iterations exceeded' limit. It seems to be the 'Maximum number of executed elements at runtime' limit that I am hitting (the limit is 2000, see the Salesforce documentation here: https://help.salesforce.com/apex/HTViewHelpDoc?id=vpm_admin_flow_limits.htm).

The reason this limit is hit is that when looping through records, each element in the loop counts as an executed element multiple times (once per record that you loop through).

For example, the simple loop below could process a maximum of 666 records:
the 3 elements in the loop * 666 = 1998 executed elements
+ fast lookup element = 1999 executed elements
+ fast update element = 2000 executed elements - the limit

Example flow

If you have additional elements inside your loop, the number of records you can process will be reduced accordingly. For example if there were four elements in my example loop, then the flow could only process (2000 - 2) / 4 = 499 records before hitting the limit. I've tested this using different numbers of records and different numbers of elements in the loop and this is definitely what was causing this error message for me. I would imagine this is also the limit you're hitting, as you say that it's adding extra elements that is reducing the number of records you can process.

I don't think that this limit is made clear enough in the Salesforce documentation, and for my purposes it makes flows essentially useless, as it seems that you can only ever loop through relatively small numbers of records using a loop.

Related Topic