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

Controller method retrieves 501 rows, coverage test fails (need workaround)

My name is Ezequiel.

I'm currently the developer for a project that we intent to release into the AppExchange market and run into a problem. In order to provide code coverage for packaging, the tests invoke custom controller's methods, which in turn query the database returning more than 500 objects, thus hitting governor limits
So, the tests don't have any query, they create their own isolated objects, but as soon as i call the controller's methods for coverage, for example, the controller queries the whole account list (that's what the controller's method is supposed to do) and it hits the dreaded 501 rows.


Is there any suggestion or help you could provide me with this ? I really don't want to change the production code if possible, i just need my tests to work bringing back only 500 rows.
Any help or assistance will be appreciated.
Thanks for your time,Ezequiel





you can apply 'Limit 10' in SOQL queries in test class.





i think ideally you want to modify the production code, and make use of e.g.  Limits.getLimitQueryRows to determine what the limit is


Unfortunately, there are no SOQL queries in test classes, the queries are in the controller.

In the test classes i only have something like 





and in the controller the method step1 queries the whole DB for objects and thus hitting the 501 limit. This works fine outside of testing, it doesn't hit any governor limits while using the app.


You can declare a variable in class and then change that variable in testmetho to true.


If test variable is true then execute the query with limit else execute the normal query.


Hope this helps you.