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
anthogiuanthogiu 

SOQL limits, Custom Metadata and flow bulkification

Hi, I'm running into a SOQL limit issue on a visual workflow.  It was my understanding that custom metadata SOQL queries did not count towards SOQL limits, but the flow element triggering the error is a Custom Metadata record lookup.

Also, according to this article, https://help.salesforce.com/articleView?id=vpm_admin_bulkification.htm, certain flow elements are supposed to be automatically bulkified by the platform, including record lookups, but that's not what I'm noticing in this case.

The flow is an autolaunched flow called from process builder.  The record lookup in question here is the first element, and in this case the only one that's getting executed because of the SOQL limit.

Can someone let me know if I'm misunderstanding one or both of these?
Gaurav HandooGaurav Handoo
Hi Anthony

I believe you need to use Fast Lookup (for default bulkification) instead of Record Lookup to ensure that the limit is not hit. That should provide you required data in a collection, which you can loop through to process your flow further.

Hope this helps!!

Cheers!!

Gaurav
anthogiuanthogiu
Thanks so much for the response!  I was starting to feel lonely lol

So, the article I referenced (https://help.salesforce.com/articleView?id=vpm_admin_bulkification.htm), claims to bulkify both types of lookup actions (record lookup AND fast lookup).  But I use fast lookup almost every time anyway, since it's easier to work with sObjects and sObject collections than it is to deal with individual variable values, and I STILL run into SOQL limit flow errors.

I believe this is either a bug, or the article is providing bad, or at least confusing, information.

Regarding SOQL limits on queries to custom metadata objects, those are not supposed to count towards the query limit in any given transaction, according to this document (http://resources.docs.salesforce.com/210/17/en-us/sfdc/pdf/salesforce_app_limits_cheatsheet.pdf).  Here's the quote from page 29:

"In a single Apex transaction, custom metadata records can have unlimited SOQL queries."

If I'm hitting any sort of SOQL query limit on a custom metadata record lookup, it sounds to me like that is not the expected behavior, unless I'm missing something, so that is an issue regardless of whether flows are bulkifying properly or not.

I tried talking to Salesforce support about these issues, but apparently they fall into the category of 'Developer Support', which requires a premium support subscription.
anthogiuanthogiu
I'm really comfortable using flows, but not quite with apex, so needless to say, it's REALLY frustrating to have this type of problem and to be unable to talk to someone at Salesforce about it, even though I've already researched and found relevant help articles / documentation that just aren't cutting it.
Gaurav HandooGaurav Handoo
Hi Anthony

Could you check if it actually is through the custom metadata that you are hitting SOQL limit or is it via another lookup happening based on the data retrieved from Metadata.

Cheers!!

Gaurav
anthogiuanthogiu
In this particular case, the metadata lookup was the first flow element, and here is the relevant info from the error email:
 
RECORD QUERY: Get_Ach_Processor_Id
Find one Record_Id__mdt record where:
DeveloperName Equals Ach_Processor_Account
Result
Failed to find record.

Error Occurred: Too many SOQL queries: 101

You may be thinking, you don't know what was going on after this mdt lookup, but the fact that it failed on THIS step and not some later step, suggests that it is NOT the case that mdt queries do not count towards the limit.  If mdt lookups are really free, then this should have been successful, and it should have failed for 101 lookups at some other point during some other query.
Gaurav HandooGaurav Handoo
Hi Anthony

Could you provide a snapshot of the flow that you have made to analyze it better.

Cheers!!

Gaurav
anthogiuanthogiu
Unfortunately, I deleted it when I had to resort to apex, but it shouldn't be hard to replicate the error.  If I find some time, I'll do that and post it here.

Thanks again!
Gaurav HandooGaurav Handoo
Hi Anthony

Will be waiting an update from you. However, I ran a test on my org (with roughly 250 records in a metadata), fetching the details through Record Lookup didn't show any SOQL error. Here I would assume that there might be some loop that is getting triggered around your lookup element and thus resulting in the error.

Cheers!!

Gaurav