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
Praetorian65Praetorian65 

System.Exception: Too many SOQL queries: 21

I have this error with an after update trigger in salesforce. The trigger definately does not do more than 8 SOQL queries at once and that is the most it can ever do. I am inserting objects via the API and I am doing them in batches. Does a batch of licences count towards this ie  4 queries + 4 queries + 4 queries + 4 queries + 4 queries = 22 queries = error? If so this is a pretty ridiculous limitation.

 

There are no loops or anything in the trigger.

Message Edited by Praetorian65 on 08-10-2009 09:32 AM
JimRaeJimRae

I have run into something similar.  It appears that all triggers for the same object, or that impact the object are all counted together in the single transaction.  For me the issue was with Opportunties.  I had 5 different opportunity triggers, plus one Opportunity Line Item trigger that all had queries.  When I tried to add a 6th trigger on the opporutnity, it would always fail with too many queries, even though, it only had 1 query.

Looking at the full debug log, I could count the queries from each of the triggers getting fired during one update DML, and sure enough, there were more than 20. 

Did some refactoring and consolidating of code and got it under the 20 limit.

Maybe that is your issue as well?

BodhiDharmaBodhiDharma
The governor limits get evaluated *per call*.  So if your trigger has DML that fires another trigger with SOQL statements, or if you call out to Apex classes with SOQL statements, these count in the limit for the original call.