function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Avinash NelluriAvinash Nelluri 

Weird Too many SOQL queries exception

Hello All,
I came across a very weird issue. In my test method, I'm running into a too many soql queries exception before even setting up my test data for a use case. So, I've moved Test.startTest() little bit upwards before the line causing 101th query hoping startTest() method will reset the limits. Surprisingly, it was still running into the same too many soql exceptions. So, I put a debug log to get total soql queries before the line that's causing the error. This time, with the debug, it doesn't throw any error. If I remove the debug, then it will run into too many soql queries.

My code:

insert somList;//This is the point I hit my 100th query. So the next query will be 101th.
System.debug(logginglevel.error, '***SOQL Count 1***'+limits.getQueries());//The debug prints 100.
Test.startTest();
System.debug(logginglevel.error, '***SOQL Count 2***'+limits.getQueries());// This debug is doing magic. If I put the debug, queries count resets. Otherwise it doesn't
List<Account> listAcnts= [SELECT ID, Name FROM Account WHERE xxxxx];//This would be the 101th query if there is no startTest() above.

Any thoughts?

Thanks,
Avinash.

 
Best Answer chosen by Avinash Nelluri
Gordon EngelGordon Engel
There is a known issue for this behavior.  It's still under review, but I think you can access it.

https://success.salesforce.com/issues_view?id=a1p30000000T5R5AAK

All Answers

Gordon EngelGordon Engel
There is a known issue for this behavior.  It's still under review, but I think you can access it.

https://success.salesforce.com/issues_view?id=a1p30000000T5R5AAK
This was selected as the best answer
Avinash NelluriAvinash Nelluri
Thank you, Gordon.