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
Sravana SudheerSravana Sudheer 

too many rows SOQL 50001 for 241actual records

Hi,
My SOQL Aggregate query returns 248 rows only but it is showing 50001 too many rows error. can anybody help me. Below is th debug logs which i found.

20:26:11.597 (4597606036)|SOQL_EXECUTE_BEGIN|[73]|Aggregations:0|select AVG(Case_Age__c) Caseage, COUNT(Id) Cnt, Program__r.Name progName, MAX(Program__c) progId from Case where Program__r.Name != null group by Program__r.Name limit 2000 20:26:13.019 (6019416719)|SOQL_EXECUTE_END|[73]|Rows:241
20:26:13.019 (6019464326)|EXCEPTION_THROWN|[73]|System.LimitException: Too many query rows: 50001
20:26:13.019 (6019747894)|SYSTEM_MODE_EXIT|false
PratikPratik (Salesforce Developers) 
Hi Sravana,

Please check in your code if loop is causing the recursion. You can also post the code so we can help you.

Thanks,
Pratik
Swayam  AroraSwayam Arora
Hi Sravana,

As you have not shared the code I am not sure but what I can see is your query is an aggregation query which means the single row which you are getting is aggregation of 1 or more rows i.e. you are getting 241 rows as result but processing has been done on more then 50000 case records.

Let me know if you need more description.

Please mark the answer as Best Answer if you find it useful.

Regards,
Swayam
Sravana SudheerSravana Sudheer
Hi Swayam Arora thank you for your response. Ya i got it now. Actually i am supposed to include Userinfo.getid in my aggregate query which i didn't before. i did it know. And it worked. Thank you. 
Swayam  AroraSwayam Arora
Welcome Sravana :).

Please mark the answer as Best Answer if it really helped so that it will help others as well in future and close the question.