function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ben Merton 17Ben Merton 17 

Visual Flow governor limits

I am trying to achieve the following function:  On a Purchase Order object, I have a bunch of Tax Line Items.  These are triggered by PO Line Items, meaning that every Purchase Order will have both PO Line Items and their associated Tax Line Items.  The number of taxes for each PO Line Item MAY be as much as five, meaning that each PO could have 5 times the number of PO Line Items.

My concern is what would happen if there were 500 PO Line Items and therefore 2500 Tax Line Items.  Would this hit governor limits on the Workflow being used to create the Tax Line Items from the PO Line Items if they were created with a flow that looks like this:

User-added image
Parker EdelmannParker Edelmann
It seems it would hit goveror limits if you generated all the PO line items at one time. It appears to me that when a PO line item is created that it'll use two SOQL querys and two DML statements. So I'd assume that it would if you created more than 50 PO line items at a time, you'd run into the "Too many SOQL queries: 101" error.
Ben Merton 17Ben Merton 17
Thanks Parker - is there any obvious way for me to change the above flow to prevent this from happening and give a much  higher limit?
Parker EdelmannParker Edelmann
The first element of the flow is a record lookup. If you could replace that lookup element by passing an sObject variable to the flow instead, you'd increase the limit to 75 because you can only make 150 DML statements, in this case Create elements. But, I found this documentation which says I'm wrong about how a flow is executed, allowing minimal resources to be used: Example of Flow Bulkification (https://developer.salesforce.com/docs/atlas.en-us.salesforce_vpm_guide.meta/salesforce_vpm_guide/vpm_admin_bulkification_example.htm)

Based on that, you should be fine for many records, as Create Elements and Lookup Elements are bulkified in the transaction. Still, you might want to pass the sObject variable to the flow in place of the Record Lookup just to make it that much more bulk.

Thanks for posting your question, it helped me learn a lot more about one of my favorite tools,
Parker
Ben Merton 17Ben Merton 17
Parker - I was also thinking that a possible solution - if it came to this - would be to have more than one flow, one of which ran on PO items with a line item number between 1 and 50, and another between 50-100,100-150 and so on?  Thanks for the link as well...
Parker EdelmannParker Edelmann
I'm afraid that idea would only escalate the situation. When you start a transaction, like importing records or generating them in other ways, it doesn't matter how many flows you use. Each transaction shares the same pool of DML and SOQL available. According to documentation, if you import 100 PO line items or a thousand, there will be two SOQL queries and two DML statements used by your flow. If you were to split it into several flows operating on records 1-50, 51-100, 101-150... it would generate 4 queries and 4 DML statements for 100 PO line items, and 40 queries and 40 DML statements for 1000 records, if it didn't use any queries to establish which flow should execute on each record. Not to mention that if you have other process automations, Process Builder, Workflow, Apex Triggers, they will also use that same set of limited resources.