0

I am trying to do a conditional, multi-level deep clone based on a hierarchy of template records.

The conditional part means that if the target record exists, then I do not update/overwrite it. I am doing the "Is Exists?" inside a loop and now getting error Too many Queries: 101 governor limit.

The flow works just fine if the number of records in the tree is small.

I am doing the Create in Bulk so that is part fine. Can't figure out an equivalent of a Map<> that I can use in flow or a equivalent of SOQL IN Clause or any other way to avoid putting the query (lookup) inside the loop.

Error happens at Fast Lookup element

Thanks in advance!

  • I am afraid you can not do it (can not use WHERE id IN collection variable). That's a reason to try to use apex invocable -- developer.salesforce.com/docs/atlas.en-us.apexcode.meta/… – kurunve Apr 13 '16 at 1:38
  • Thanks! for confirming. I was hoping there was something I was missing and I could avoid apex (and test classes) but looks like code it is. – zepz Apr 13 '16 at 1:56
  • Anytime you run a DML in a loop, you will probably hit this error. All lookups, updates, creates and deletes should be avoiding inside a loop to prevent hitting max queries. It's almost a sure thing if you do. – markross__c Apr 13 '16 at 13:45
  • Hi markross__c, exactly, trying to get the query out of loop. any idea on how to do that in this scenario? – zepz Apr 13 '16 at 14:14
1

There are 2 alternatives of avoiding too many soql queries in a flow, and without using Apex.

  1. You can try using the Wait element.
  2. Or a not so useful but an option that works is to introduce another screen in the loop. This splits the transaction.

Hope this helps. Let me know if you need more information.

  • SfdcFanBoy, do you know if Wait element only adds a delay or does it create a new execution flow and context? If latter then I can get increased governor limits. – zepz Apr 13 '16 at 14:11
  • It starts a new transaction. – sfdcFanBoy Apr 14 '16 at 8:56
  • 1
    Thanks. I checked out the Wait element and looks like the min duration for that is 1 hour, so I guess I need to go the Apex route. – zepz Apr 19 '16 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.