Salesforce Certified Application Architect

Tuesday 14 October 2014

System.LimitException: Too many SOQL queries: 101 – while moving into production

This exception is one of the common governor limits that a salesforce developer experiences. Generally we would get this exception when the code is not written properly . ie. You have a SOQL query with in a for loop.

But many a times while deploying a trigger or class to production i get ths error. I check and double check if there were any SOQL queries within a for loop. But nothing in the class or trigger has the SOQL with in a loop and this is reflected in a different test class other than the code you are moving into production.

This happens because we would not have used the Test.startTest() and Test.stopTest() methods in our test classes. All the DML operations for setting the data for execution of test should be done before the Test.startTest() method and all the actions for testing your code should be between Test.startTest() and Test.stopTest() methods.

What this does is that it gives context to your test class. In other words only the code executed between the Test.startTest() and Test.stopTest() would be considered in the governor limit calculations. If there are no Test.startTest() and Test.stopTest() then all the setup code and actual test code would count towards the limits.


No comments:

Post a Comment

Salesforce Certified Application Architect & Certified Data Architecture and Management Designer Exam

How to pass Salesforce Certified Data Architecture and Management Designer Exam This exam was 1st architect exam for me. Its not that muc...