I have a requirement to send mass emails to certain Users of current day created records daily.
I am unable to do that with below code.
Getting error :
Aggregate query does not support queryMore()
Please let me know a way out of this.
Code:
global class Incidentimp implements Database.Batchable<sObject> {
public string query = 'SELECT DM_Lookup_id__c,DM_Lookup_id__r.name FROM Incident__c where createddate<>today
group by DM_Lookup_id__c,DM_Lookup_id__r.name';
global database.querylocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, Sobject[] scope)
{
//Map<Inventory_Wishlist__c, Product2> temp = new Map<Inventory_Wishlist__c, Product2>();
// Set<string> accountIdSet = new Set<string> {};
// Map<string,string> xyz=new Map<string,string>();
EmailTemplate emailTemplate = [select Id, Body from EmailTemplate where DeveloperName = 'POC_DM'];
for (Incident__c item : (List<Incident__c>)scope) {
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setToAddresses(new String[] {'saikat.neogy@cognizant.com'});
email.setTemplateId(emailTemplate.Id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
}
}
global void finish(Database.BatchableContext BC) {
}
}
Best Answer
May be your "scope" returning more than 2000 registers. You should read answers for that question > System.QueryException: Aggregate query does not support queryMore() Specially the answer by Daniel