Loading

Exceeded Execution Governors Limit - Error: System.LimitException: Too many SOQL queries: 101

Publish Date: May 29, 2026
Description

The following error appears when you exceed the Apex Execution Governor Limit for SOQL queries: System.LimitException: Too many SOQL queries: 101
Salesforce Apex runs on a shared, multi-tenant platform where all customers share the same computing resources. To ensure no single customer's code monopolizes shared resources, Salesforce enforces governor limits. The SOQL query governor limit is capped at 100 queries per transaction context — including all SOQL queries fired by triggers, classes, flows, and API calls within that single context.
When this limit is exceeded, Salesforce throws the LimitException shown above.
Real-world example: An Apex trigger on the Account object queries related Contacts for each Account in a batch. If 101 Accounts are processed in a single transaction and the trigger fires one SOQL query per Account record (inside a for loop), the limit is exceeded on the 101st Account and the transaction fails.
Notes:

  • All SOQL queries in triggers fired from one call or context count against the limit of 100.
  • Salesforce cannot disable or raise the Governor Limit.
Resolution

Resolve the "Too many SOQL queries: 101" Error

To fix this issue, refactor your Apex code so that the total number of SOQL queries fired within a single transaction context is fewer than 100.
If you need to run code asynchronously to avoid the limit in the current context, use the @future annotation, which executes the code in a separate, asynchronous transaction with its own governor limit allocation.

Best Practices to Avoid Exceeding the Governor Limit

Since Apex runs on a multi-tenant platform, the Apex runtime engine strictly enforces limits to ensure code does not monopolize shared resources. Follow these best practices to stay within the 100-query limit:

  • Avoid SOQL queries inside FOR loops. Never place a SOQL query inside a loop that iterates over records. Instead, collect the record IDs first, then run a single SOQL query outside the loop using an IN clause with all the IDs.
  • Bulkify your Apex code. Design triggers and classes to handle multiple records in a single transaction (bulk operations) rather than processing records one at a time.
  • Review Apex Code Best Practices. Follow the key coding principles in the Salesforce Apex Code Developer's Guide.
  • Review Trigger and Bulk Request Best Practices. Review the Salesforce documentation on best practices for triggers and bulk API requests.

 

Knowledge Article Number

000386220

 
Loading
Salesforce Help | Article