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
Developer_shaanDeveloper_shaan 

Too many query rows exception in aggregate function implementation

Hi,

 

error while using aggregate function.

System.LimitException: Too many query rows: 58309


SELECT SUM(RI_Production_Goals_Next_Year__c) FROM Contact  WHERE recordtypeid = '012400000005OLAAA2'

 

how to avoid this??

 

 

SurekaSureka

Hi,

 

You need to limit the number of records by specifying the limit or include some more filters like recordtype.

 

Thanks

Developer_shaanDeveloper_shaan

Thanks for the reply surekha,

i have tried it using limit and the group by and order by clauses  in SOQL query.

 

 

SELECT id, SUM(RI_Production_Goals_Next_Year__c) FROM Contact  WHERE recordtypeid = '012400000005OLAAA2' group by id Limit 1000

 

but now tyeh error  is:

 

System.UnexpectedException: Internal Salesforce.com Query Error

 

please let me  know whats wrong with the query??

 

I also tried using order by and group clause to gether but  the same error is being thrown.

 


 

Thanks

shaan

Developer_shaanDeveloper_shaan

Have you found any soln for this.

Limit s not working properly when  applied on queries with aggragate functions.

DmitriyRybalskyDmitriyRybalsky

The same problem.

I have ~2000 accounts

Simple query [SELECT count() FROM Account]; in test method throwing Too many query rows: 501