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

system.exception too many query rows 501

can anybody explain me what is this error.I am trying to deploy a contoller class and visualforce page into production and i am geting this error.


system.limit.exception:    Too many query rows 501.


The most likely reason is that you have some existing data in your production that isn't available in the sandbox. When you run your test classes during deployment, the total SOQL limit is being reached.


You could prevent this by using System.runAs()


More information can be found at :<Tech>+Germ)


Hope it helps!


hi Xhitman,


i tried using the system.runAs(). But still I am facing the same problem.


Have you tried checking the deployment log to see if you are reaching the limit?


Try to look for something like:

Number of query rows: 2392 out of 10000


i saw the deployment log i dont see anything like that saying 


I use Limits.getLimitQueryRows to get passed this problem...limit your query by a integer set to this value, and then it will automatically limit test queries when you are deploying code without limiting queries when then run in Production


You could try @BritishBoyinDC's suggestion to explicitly show the current limits in the debug logs so that you will see how much you have used so far.


I also tried system.runAs() but negative.

The best solution is to run the test between starttest and stoptest.




Sample Code:



Your code