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
Nitzan MarinovNitzan Marinov 

Too many SOQL queries in Flow

Hi all,

I created a screen flow that updates a number of Payment records for the opportunity that the user wants to update.
Full screen shots are in this post (https://trailblazers.salesforce.com/answers?id=9064S000000D6aK), in the answer marked Best Answer.

I now want to run it as a one off process to update all Payment records for all opportunities. So I created a slightly different version of the screen flow (without a confirmation screen*) and a calling screen flow that gets all existing opportunity records and calls the updating flow for every opportunity. *The only reason this is a screen flow is that I created it from the original version and it won't let me change the flow type from a screen flow to an auto-launch flow without re-writing the flow.

Both flows work on a small number of opportunities but when I try to run them for all opportunities (We only have 250), I get this error message:

Error element Update_varPaymentUpdList_Records (FlowRecordUpdate).
The flow tried to update these records: null. This error occurred: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: npsp.TDTM_Payment: System.LimitException: npsp:Too many SOQL queries: 101. You can look up ExceptionCode values in the SOAP API Developer Guide (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_concepts_core_data_objects.htm" style="color:blue; text-decoration:underline).---The flow tried to update these records: null. This error occurred: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: npsp.TDTM_Payment: System.LimitException: npsp:Too many SOQL queries: 101. You can look up ExceptionCode values in the SOAP API Developer Guide (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_concepts_core_data_objects.htm" style="color:blue; text-decoration:underline).


I can create a work-around by only running the process in small batches manually (with adding an indication on the opportunity object to let me know if the record was already processed. But I wonder if there is an easier/more clever way of resolving this.

Many thanks!
ShirishaShirisha (Salesforce Developers) 
Hi Nitzan,

Greetings!

Each flow interview runs in the context of a transaction. A transaction represents a set of operations that are executed as a single unit.  For example, a transaction can execute Apex triggers and escalation rules in addition to a flow interview. If one interview in a transaction fails, all the interviews in the transaction are rolled back, as well as anything else the transaction did. The transaction doesn’t retry any of the operations—including the flow interview.

If you think that a flow’s interview is likely to hit governor limits within its transaction, consider adding a Wait element or a Screen element.

As per the screenshots that I have checked inthe post,I would suggest you to drop wait element while updating the records to avoid hitting governor limits.

Here,I am providing the blog which will guide you on how to use Wait element in the flow:

https://salesforcesidekick.com/2015/03/27/how-to-use-the-wait-element/#:~:text=RECAP%3A%20Wait%20elements%20are%20your,it%20directly%20into%20your%20Flow!

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
Nitzan MarinovNitzan Marinov
Hi Shirisha,

Thanks for providing your support.

It looks like I would have to convert my flow (i.e., re-write it) to an auto-launch flow as Pause (as it is now called), is not allowed in a screen flow.

I looked at how to use a pause (as described in the blog you referred to) and I'm not quite sure how this is going to work for me. When you suggested that I used the Pause/Wait element, did you mean that I would introduce a simple delay or that I check to see that payment records are updated before I try to update the next opportunity?

If it's the first, I'm not sure how that would work as the minimum absolute time unit is an hour and that seems far too long to wait.

If it's the second, you say: "I would suggest you to drop wait element while updating the records to avoid hitting governor limits." Do you mean that I need to:
  • Update payment records for the opportunity (after Last Loop Item)
  • Introduce pause
I am not sure how to define the "pause conditions" and the "resume event" - can you please say a bit more to clarify this for me?

Thanks
Nitzan

 
Nitzan MarinovNitzan Marinov
Update: I was able to play with a newly created auto-launch flow and I created a Pause element. I understand that I can:
  1. Run the Update Records
  2. Call the Pause element with a pause condition that the Update Records element was visited
  3. Define the Resume Event as the date/time of the flow with a 0 hour offset
But the Pause element needs to be called and then call another element and I'm not sure how to structure it so that the Pause happens after the records are updated and then quits the flow to allow it to be called again from the calling screen flow.