Below is information on how to troubleshoot errors when hitting Salesforce's governor limits.
Error: Too many SOQL executions: 201.
Situation: Error occurs when closing an Account Period.
This error is due to certain code breaking Salesforce’s governor limits for Total Number of SOQL queries issued in an Apex transaction, which means you can run up to a total 200 SOQL queries in a single call or execution context. Whenever any of the governor limits are crossed, Salesforce will throw an error and halt the execution of code.
The error message tells us at exactly which line of certain code that we breached the governor limit. To fix the issue, you'll need to change your code in such a way that the number of SOQL fired is less than 200.
To debug the issue follow the below steps:
- In the client’s org, go to Setup and search for Debug Levels.
- Click New.
- Name: SOQL Error
- Set all Categories to INFO except >>> Apex Profiling: Finest
- Next to User Trace Flags click New.
- Traced Entity Type: User
- Traced Entity Name: Find the user that you logged into client’s org as.
- Start Date: Current time
- Expiration Date: 30 min from the current time
- Debug Level type: SOQL Error
- Click Save.
- The 1st grouping is the Number of SOQL queries generated by client’s code.
- The 2nd grouping is the Number of SOQL queries generated by AS’s code.
- Keep going down the Debug Log until you see >>> Number of SOQL queries: 201 out of 200 ******* CLOSE TO LIMIT
- CODE_UNIT_STARTED|[EXTERNAL]|01q6F000000hKNT|DEL_XYZ on Billing trigger event AfterUpdate|__sfdc_trigger/DEL_XYZ
- Number of SOQL queries: 103 out of 200 ******* CLOSE TO LIMIT
- This will show how many SOQL queries were generated by the method DEL_GSTLinesforBillings. In this case it is 98, before the code crashed
- What is an asynchronous process?
- What is a governor limit?
Article is closed for comments.