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.


1 Answer 1


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.

  • The governor limit he's hitting is too many queries, and not too many rows...how would this affect the number of queries? Apr 7, 2015 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, 2015 at 16:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .