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
groundwiredgroundwired 

aggregate query with batch apex

Are the new aggregate queries supposed to work with batch apex?  I didn't find anything that says it is unsupported, but I sent a "group by rollup" query to a batch class, and got this error:

 

System.Exception: Aggregate query does not support queryMore(), use LIMIT to restrict the results to a single batch

 

Any ideas?

 

mcfarlpmcfarlp
I'm having this issue as well. The workaround stated in the exception is silly. If you add a LIMIT to the GROUP BY query the aggregate result (e.g. COUNT) will be incomplete/incorrect which defeats the purpose of using the aggregate function.
jesperfjjesperfj

The LIMIT clause limits the number of final output rows. It doesn't limit the rows that the aggregation is based on.

groundwiredgroundwired

If you are right, jesperfj, then there is no way to issue a group by query without risking an unhandled exception by hitting limits.  According to a new note in the documentation, the governor limits are based on the number of rows you aggregate, not the rows returned - but how would you know ahead of time how many you are going to affect?  This is a problem that Salesforce needs to address soon.  

 

Speaking of problems, has anyone else been hitting "Internal Server Error" bugs in Salesforce when running aggregate queries (GROUP BY ROLLUP, GROUP BY CUBE)?  I have built an application that runs fine one day, and then causes these unhandled exceptions the next - seems to be completely random.  Have logged a case (03416031) but would be interested to hear if anyone has seen this.

 

Message Edited by groundwired on 03-23-2010 04:23 PM
kool_akool_a

I get a salesforce internal error also. Same situation when i use the aggregate function in SOQL like Max, Having and group by) and its random, I have this SOQL running in a batch that is schedule to run every night. The errors are random and i can't find a pattern. If anyone has ideas please share . Sample error below

 

Salesforce System Error: 226624809-1628 (1928603964) (1928603964)

 

 

Thanks

dmchengdmcheng

I've run into the "Aggregate query does not support queryMore()" error also.  Very frustrating.  I'm running this in a full copy sandbox and I invoked the batch using execute anonymous.