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
kumarcrm bingikumarcrm bingi 

delete duplicate record . that why i write the batch apex

EXCEPTION_THROWN [7]|System.QueryException: Aggregate query does not support queryMore(), use LIMIT to restrict the results to a single batch

global class DuplicateEmailCheck implements Database.Batchable<sObject>, Database.Stateful
{
   
    global Database.querylocator start(Database.BatchableContext BC)
    {
        string qurey = 'select CmEventID__c from task GROUP BY CmEventID__c HAVING COUNT(CmEventID__c) > 1';
        //The below query returns all the emailId which has more than one entry
        return Database.getQueryLocator(qurey);
    }
global void execute(Database.BatchableContext BC, List<AggregateResult> scope){
    Set<String> arEmailId = new set<String>();
    //Below loop is to collect all the email ids from aggregateresult of start method to a set which will be used to filter records .
    for (AggregateResult ar : scope)
    {
           arEmailId.add((String)ar.get('CmEventID__c'));
    }
 List<task> fanList = [select CmEventID__c,id from task  where CmEventID__c in :arEmailId];
 delete fanList;
}    
global void finish(Database.BatchableContext BC)
{
}
}