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
fdacruzfdacruz 

Flow Error - too many SOQL queries: 101

I was under the impression that Flows were automatically bulkified, but every time that one of my users uploads a list to SF, I get the error below.

Can someone provide a tips to help with this? The flow is being triggered by a process.
 

Error element Lead_Lookup (FlowRecordLookup).
This error occurred when the flow tried to look up records: Too many SOQL queries: 101. For details, see API Exceptions.
This report lists the elements that the flow interview executed. The report is a beta feature.
We welcome your feedback on IdeaExchange.
Flow Details
Flow Name: Lead_Datestamp_Update
Type: Autolaunched Flow
Version: 10
Status: Active
Flow Interview Details
Interview Label: 
Current User: Felipe Da Cruz (00541000001TeSw)
Start time: 7/20/2017 2:52 PM
Duration: 0 seconds
How the Interview Started
Felipe Da Cruz (00541000001TeSw) started the flow interview.
Some of this flow's variables were set when the interview started.
OldStatus = Working
LeadId = 00Q4100000KYN1HEAX
FAST LOOKUP: Lead_Lookup
Find all Lead records where:
Id Equals {!LeadId} (00Q4100000KYN1HEAX)
Assign those records to {!Lead}.
Save these field values in the variable: Datestamp_Nurturing__c, Datestamp_Ready__c, Datestamp_Working__c, Datestamp_DQ__c, Datestamp_Qualified__c, Datestamp_Qualified_Rejected__c, Datestamp_Lead_Conversion__c, Status, Cycle_Counter__c, Ready_Source__c, Ready_Channel__c, Last_DQ_Rejection_Reason__c, DQ_Rejected_Reason__c, MQL_Created__c, Notification_Sent_Robin_Ready__c
Result
Successfully found records.

FAST LOOKUP: Lead_Lookup
Find all Lead records where:
Id Equals {!LeadId} (00Q4100000KYN1HEAX)
Assign those records to {!Lead}.
Save these field values in the variable: Datestamp_Nurturing__c, Datestamp_Ready__c, Datestamp_Working__c, Datestamp_DQ__c, Datestamp_Qualified__c, Datestamp_Qualified_Rejected__c, Datestamp_Lead_Conversion__c, Status, Cycle_Counter__c, Ready_Source__c, Ready_Channel__c, Last_DQ_Rejection_Reason__c, DQ_Rejected_Reason__c, MQL_Created__c, Notification_Sent_Robin_Ready__c
Result
Failed to find records.

Error Occurred: Too many SOQL queries: 101
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi,

You would probably get this error when you hit the Execution Governors limit, which means you can run a total 100 SOQL queries in a context.  All the triggers fired will be counted in a single context. Hope it will be helpful.

Please mark it as best answer if the information is informative.

Thanks
Rahul Kumar
fdacruzfdacruz
Hi Rahul - thanks for the answer.

What would help me understand is a clarification of what is meant by "all triggers fired will be counted in a single context".

Does this mean that if I perform a bulk upload of over 100 records, a Process Builder trigger will be triggered for each record and thus over 100 SOQL queries (from the autolaunched Flow) are executed puting me over the governor limit?

That would imply that bulkification does not work with Process Builder + Flow triggers.

(I have used Fast Lookup given the advice in some of the threads that I read and other Salesforce reference material)
doughauck-corpdoughauck-corp
The "context" in the case of a Flow is the Flow's transaction.  From the Visual Workflow Guide (don't worry - I'll unravel it afterward):

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.

The flow's transaction starts at the least when the flow starts, though it might actually start with whatever called the flow - Process, Trigger, VF Page, etc.  That could be important if one Process calls several Flows, for example, but I don't know if it applies to your situation.

The transaction ends when the flow ends, or (as with the multi-Flow Process example above) when its caller ends.  EXCEPT... if your Flow contains a Screen or a Wait element, then the transaction will end at that element, and a new transaction (with refreshed governor limits) will start when the Flow moves on from that element.  In fact, the VWF Guide explicitly states:

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.

So I think that is your solution - either keep count of the number of operations or look for likely places where you could overflow limits, and either drop a Wait element (for an Autolaunched Flow) or a Screen element (for manually launched Flows).  How you do that... well, that's another question.