You need to sign in to do that
Don't have an account?
kumarcrm 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)
{
}
}
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)
{
}
}