+ Start a Discussion
santhosh  konsanthosh kon 

How to delete inactive accounts by Batch Apex please send me some sample code?

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

global class BatchDeleteInactiveAccounts implements  Database.Batchable<sObject> {

//Modify filter conditions as per your org needs
global string query = 'select Id from Account where Active__c = false';

global Database.QueryLocator start(Database.BatchableContext BC){
 
    return Database.getQueryLocator(query);
}

global void execute(Database.BatchableContext BC, List<sObject> scope){

  Database.delete(scope,false);  

}

global void finish(Database.BatchableContext BC){
}

}