Print this page

System.LimitException: Too many SOQL queries: 101

Knowledge Article Number 000181404
Description The "System.LimitException: Too many SOQL queries: 101" error appears when you've hit the Execution Governor Limit, which means you can run up to a total 100 SOQL queries in a single call or context.  All the SOQL queries in triggers fired from one call or context will be counted against the limit of 100.
Resolution To fix the issue, you'll need to change your code in such a way that the number of SOQL fired is less than 100. If you need to change the context then you can use @future annotation which will run the code asynchronously.

Here are some best practices that will stop the error messages and/or help you avoid hitting the Governors Limit: 

1. Since Apex runs on a multi-tenant platform, the Apex runtime engine strictly enforces limits to ensure code doesn't monopolize shared resources. Learn about the Governors Limit.
2. Avoid SOQL queries that are inside FOR loops
3. Check out the Salesforce Developer Blog where you can find Best Practices for Triggers.
4. Review best practices for Trigger and Bulk requests on our Apex Code Developer's Guide. 
5. Be sure you're following the key coding principals for Apex Code in our Developer's Guide.

Important: Salesforce cannot disable the Governors Limit or raise it. Following the best practices above should ensure that you don't hit this limit in the future.

promote demote