Too many SOQL queries : 101

Error: System.LimitException: Too many SOQL queries : 101

APEX

The following error appears when you exceed the Execution Governors Limit (you can run up to a total 100 SOQL queries in a single call or context). 

System.LimitException: Too many SOQL queries: 101 error

Notes:

  • All the SOQL queries in triggers fired from one call or context will be counted against the limit of 100.
  • Salesforce cannot disable or raise the Governors Limit.

Resolution


Resolve the “Too many SOQL queries: 101” error

To fix the issue, change your code so that the number of SOQL fired is less than 100.

If you need to change the context, you can use @future annotation which will run the code asynchronously.
 

Best practices to avoid exceeding the Governors Limit

Since Apex runs on a multi-tenant platform, the Apex runtime engine strictly enforces limits to ensure code doesn’t monopolize shared resources.
 

Leave a Reply