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
krishnagkrishnag 

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.

XhitmanXhitman

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 :http://www.tgerm.com/2010/05/systemrunas-501-apex-query-rows.html?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed:+TechnologyGerm+(<Tech>+Germ)

 

Hope it helps!

krishnagkrishnag

hi Xhitman,

 

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

XhitmanXhitman

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

krishnagkrishnag

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

BritishBoyinDCBritishBoyinDC

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

XhitmanXhitman

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.

suresh_cssuresh_cs

I also tried system.runAs() but negative.

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

 

test.test.startTest();
test.stopTest();

 

http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods

 

Sample Code:

 

test.startTest();

Your code

.....

......

test.stopTest();

 

cheers