Too many SOQL queries: 101
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Bulkify your trigger and move queries outside loops.
Problem Explanation
Salesforce enforces a governor limit of 100 SOQL queries per transaction. Queries inside loops multiply quickly and exceed this limit.
Root Cause(s)
1. SOQL inside
forloops2. Multiple triggers on the same object
3. Recursive trigger execution
Step-by-Step Solution
1. Collect record IDs into a
Set<Id>2. Run one SOQL query using
WHERE Id IN :idSet3. Store results in a
Map<Id, SObject>4. Access data from the map inside loops
Map<Id, Account> accMap = new Map<Id, Account>(
[SELECT Id, Name FROM Account WHERE Id IN :accIds]
);
Edge Cases & Variations
1. Use
Trigger.newMapin update triggers2. Watch for workflow or Flow-triggered recursion
Common Mistakes to Avoid
1. Querying per record
2. Ignoring recursion guards
3. Using
Limits.getQueries()only for logging