You need to sign in to do that
Don't have an account?

Error in batch apex
Hi,
Can someone please help me understand how to avoid the below error in the batch:
Aggregate query has too many rows for direct assignment, use FOR loop
The batch uses the below query:
SELECT Id, Type, Potential_Revenue__c, (SELECT Id, Total_Perm_Value__c, CreatedDate, Contract_Type__c, Status, Account_End_Date__c from Agreements where status != \'Activated\') From Account';
And the error comes in at the below line of code:
global void execute(Database.BatchableContext BC, List<sObject> scope)
{
for(sobject s : scope)
{
Account a = (Account) s;
custIndicator = 0;
if(a.Agreements != null && a.Agreements.size() > 0) <--------- Error comes here.
{
thanks a lot!!
See this thread:
http://boards.developerforce.com/t5/Apex-Code-Development/Aggregate-query-has-too-many-rows-for-direct-assignment-use-for/td-p/309145
This limit does not appear to be documented anywhere. You will probably have to omit the subquery from your initial batch query, then retrieve the Agreement records in the batch execute method.
All Answers
try:
global void execute(Database.BatchableContext BC, List<sObject> scope)
{
for(sobject s : scope)
{
Account a = (Account) s;
custIndicator = 0;
for(Agreements agr : a.agreements){
//do stuff
}
{
Hi,
Thanks so much for the help. Really appreciate it but i am using the for loop as below but am still getting the error:
global void execute(Database.BatchableContext BC, List<sObject> scope)
{
for(sobject s : scope)
{
Account a = (Account) s;
custIndicator = 0;
if(a.Agreements != null && a.Agreements.size() > 0) <--------- Error comes here.
{
for(Integer i = 0; i < a.Agreements.size(); i++)
{
if(custIndicator <= 0)
{
if(a.Agreements[i].Agreements_Type__c == 'Value')
{
custIndicator++;
break;
}
}
}
This Line: if(a.Agreements != null && a.Agreements.size() > 0) <--------- Error comes here.
{
is where you are having issues.
Which is why if you look at my example I removed it. For each record, I then loop through the children. That is where you do your processing. Try the example I provided...
Hi,
Sure will do and respond back with the results.
Regards
See this thread:
http://boards.developerforce.com/t5/Apex-Code-Development/Aggregate-query-has-too-many-rows-for-direct-assignment-use-for/td-p/309145
This limit does not appear to be documented anywhere. You will probably have to omit the subquery from your initial batch query, then retrieve the Agreement records in the batch execute method.