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
dev_forcedev_force 

Governor Limit - Total number of records retrieved by SOQL queries

Why is it that "Total number of records retrieved by SOQL queries" is:

10,000 - anonymous block, visualforce controller or WSDL method

BUT

500 for RunTests 

 ?

 

My code can handle more than 10,000 rows, but my test class fails because tests can only operate within the 500 limit.  Even though my test class does not create more than 500 records, the test class/method seems to operate on the data in the actual org plus the data created in the test class/method.

 

 

Please advise.

Best Answer chosen by Admin (Salesforce Developers) 
bob17bob17

1. You could code your query to include a LIMIT vale set based on the lesser of 10,000 or the the number of rows remaining in the queried rows limit:

 

maxQueryRows = Limits.getLimitQueryRows() - Limits.getQueryRows();

 

2. Your obsevation about the database data in scope of yourtest is correct - tests see the data created by the test PLUS and data that exists in the org in which the test is run.  You can either delete all existing data that would be "seen" by your test at the start of the test (watch out forlimits here) or create very unique data at the start of your test (not always possible I know).

 

3. I agree that this is still a problem.  I am trying to test some new code right now that has significant processing when a query returns 1,000 rows and I can't get tests to reach that condition because of the 500 row limit with test methods.  Yes, I know I can probably restructure the code to call a separate routine when the limit is encountered and then have tests call the handling routine directly but it does not seem right that we have to write bloated and inefficient code just because SFDC won't let tests run in a true simulated production environment.

 

Anyone have any ideas / recommendations?