4

I was trying to deploy a trigger from sandbox to production but was unable to do so as test run was throwing error Too many SOQL query. I tried all the best practices to avoid error too many soql query but was unable to resolve this.

But changing API versions from 23 to 33.0 solved my problem.

My question is how API version makes any difference to SOQL queries in test class.

11

The IsTest(SeeAllData=true) Annotation was introduced in API 24. In API 23 or less the tests could see all the data in your org. This would mean your SOQL queries are returning a lot of data and if you have a SOQL query in a for loop that iterates over data then the query will get called more than you expected. In API 24 and above, by default, the tests did not see any data so your queries are returning less data.

It sounds like you may have a SOQL statement in a for loop somewhere in your code.

| improve this answer | |
  • The governor limit he's hitting is too many queries, and not too many rows...how would this affect the number of queries? – Brian Mansfield Apr 7 '15 at 16:04
  • 4
    If there is a SOQL query in a for loop that iterates over records then the more data that is in the app the more times the SOQL query gets called. – BarCotter Apr 7 '15 at 16:36

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.