I am in critical situation due to below error

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

Whenever we are moving any changeset to production we are getting the above error. We followed salesforce best practices to write apex classes and triggers. We tried Test.start() and Test.stop to refresh the soql query count but no use of this because we are having too many queries that are hitting in various triggers.

Also we are not able to see the full debug log due to 2MB size limit.

Is there any other way to overcome this?


  • 3
    you can review a code that cause it and find an issue in that triggers. you can also add something like if (Limit.getQueries() > 90) { throw new customException('Here'); } to get place where limit is almost out. – kurunve Aug 25 '16 at 8:03
  • 4
    You can make a support request to get the 2M limit raised and then use tools like this SOQL Extractor and Analyzer for Salesforce (awkward to get installed though - see its "Support" information for a workaround) to help review the logs. Typically you will see repeated queries caused by cycles in the trigger and workflow logic - not easy to find the cause or fix. – Keith C Aug 25 '16 at 8:04
  • 6
    You can also change the log levels to lessen the log size. – rael_kid Aug 25 '16 at 8:05
  • Try to make your trigger deactivatable per some custom setting... – Sergej Utko Aug 25 '16 at 8:05
  • @kurunve - 1. am not able to see the debug of the code i want due to maximum debug size reached. 2. could you please put example for limit.getQueries() – mohammed azarudeen Aug 25 '16 at 8:10

Open the Developer Console, choose Debug / Change Log Levels... Click Add/Change next to the top entry, set all categories to None, except Profiling, which you set to Finest. Next, run your tests, then check the logs. You'll get a list of queries executed, plus the class or trigger that called them, and the number of executions. You can use Profiling to quickly identify where the most usage is occurring.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.