You need to sign in to do that
Don't have an account?
URGENT - Aggregate query does not support queryMore(), use LIMIT...
Sigh, so I've hit another odd error with not much to be found on google. I have a simple aggregate query that effetivly acts as a rollup.
AggregateResult[] campaignTotals = [select SUM(Actual_Male_Quota__c)males, SUM(Actual_Female_Quota__c)females, SUM(total_Respondents__c)total, SUM(Total_Master_Caller_Recruits__c)caller, SUM(Total_Master_IVR_Recruits__c)ivr, SUM(Total_Master_Web_Recruits__c)web, parentId From Campaign where isActive = true and recordTypeID = :ParentRecordType.id and parentId != null group by parentId LIMIT 500];
And I'm getting the error
Failure Message: "System.Exception: Aggregate query does not support queryMore(), use LIMIT to restrict the results to a single batch", Failure Stack Trace: "Class.UpdateTopLevelCampaignCounters.updateCountersTrigger: line 14, column 45 Class.unitTests.testUpdateUmbrellaCounters: line 335, column 36 External entry point"
I decided to include a limit statment (even though I think that would basically cause this query to be useless since it will likely return junk results but as a test I figured it was worth it. That still didn't resolve it. Is the limit lower? Is there something else I should be doing here instead? Below is the full code for the trigger.
WebService static boolean updateCountersTrigger() { try { RecordType ParentRecordType = [select id from RecordType where name = 'FPI Parent Campaign']; Campaign[] updateCampaigns = new Campaign[]{}; AggregateResult[] campaignTotals = [select SUM(Actual_Male_Quota__c)males, SUM(Actual_Female_Quota__c)females, SUM(total_Respondents__c)total, SUM(Total_Master_Caller_Recruits__c)caller, SUM(Total_Master_IVR_Recruits__c)ivr, SUM(Total_Master_Web_Recruits__c)web, parentId From Campaign where isActive = true and recordTypeID = :ParentRecordType.id and parentId != null group by parentId LIMIT 500]; //Loop over the aggregate result set for (AggregateResult ar : campaignTotals) { Campaign thisCampaign = new Campaign(Id=String.valueOf(ar.get('parentId'))); thisCampaign.Total_Project_Males__c = double.valueOf(ar.get('males')); thisCampaign.Total_Project_Females__c = double.valueOf(ar.get('females')); thisCampaign.Total_Project_Caller_Recruits__c = double.valueOf(ar.get('caller')); thisCampaign.Total_Project_IVR_Recruits__c = double.valueOf(ar.get('ivr')); thisCampaign.Total_Project_WEb_Recruits__c = double.valueOf(ar.get('web')); thisCampaign.Total_Project_Respondents__c = double.valueOf(ar.get('total')); thisCampaign.Global_Counters_Last_Updated__c =System.now(); //Add this new account to the list of account objects updateCampaigns.add(thisCampaign); } //Update the account object. update updateCampaigns; return true; } catch(Exception e) { return false; } }
|
Hi Kenji775,
First, we cannot give limit on the aggregate queries because, the limit in aggregate queries limits only the no.of aggregate results but not the actual no.of rows being retrieved.
The fix for this would be either add more conditions to limit the no.of rows that the soql is trying to retrieve (or) if we need to process all the records, use asynchronous calls / batch apex
@User@SVF
fyi, this issue still happens in batch apex