global with sharing class BatchDelete implements Database.Batchable<SObject> {
SObjectType entityType;
Integer limitCount;
global BatchDelete(SObjectType entityType, Integer limitCount) {
this.entityType = entityType;
this.limitCount = limitCount==null?50000000:limitCount;
}
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('SELECT Id FROM '+String.valueOf(entityType)+' LIMIT '+String.valueOf(limitCount));
}
global void execute(Database.batchableContext bc, sobject[] scope) {
database.delete(scope,false);
}
global void finish(database.batchablecontext bc) {
}
}
You can adapt this to a specific type of sobject, or change the deletion behavior, possibly even track number of failures and so on. This is just a quick example of how you might get started.
You can adapt this to a specific type of sobject, or change the deletion behavior, possibly even track number of failures and so on. This is just a quick example of how you might get started.