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
MythiliMythili 

@ReadOnly thorwing System.LimitException: Too many query rows: 50001 error

I have nearly 300,000 account records in my org. I have the following class in my org:
global class testReadOnly{
@ReadOnly webservice static List getAcc()
{ return([select id from Account]); }
}
When I tried calling this method like testReadOnly.getAcc(); I get the following error:EXCEPTION: System.LimitException: Too many query rows: 50001
 Documentation says @ReadOnly returns upto 1 million rows. Please note that I have not performed any DML, sent emails or anything else in this transaction.
Can anyone tell me why am I getting the error even though I use @ReadOnly annotation. Thanks.
VineetKumarVineetKumar
The @ReadOnly annotation is available for Web services and the Schedulable interface. To use the @ReadOnly annotation, the top level request must be in the schedule execution or the Web service invocation. For example, if a Visualforce page calls a Web service that contains the @ReadOnly annotation, the request fails because Visualforce is the top level request, not the Web service.

Hope you are not violating the above highlighted part?
MythiliMythili
Yep I read this in the documentation. I am not violating.
VineetKumarVineetKumar
I suppose you are runing your method : testReadOnly.getAcc(); from a developer console or from execute anonymous.
If yes, the your top level call is not a webservice call.
MythiliMythili
Yes you are right. I am calling from workbench.So should I import the wsdl and call the method using the class generated from wsdl?
VineetKumarVineetKumar
Yep..

Do mark my answer as best answer if it helped solve your problem
MythiliMythili
Thanks a lot for your prompt response.How is that calling this method from developer console not a top level request? I am calling this method directly only right..
VineetKumarVineetKumar
Well it looks so at top level, but the developer console also send an API call to salesforce to execute something.
You can refer the debug logs and see, it says Type = API