You need to sign in to do that
Don't have an account?

Batch Apex - Performance problem deleting large sets of data
Hi -
I am looking for the fastest way possible to mass delete all records for a given custom object. I developed a very simple Batch Apex class which is described below. The code works but it performs very slowly. Yesterday it took 40 minutes to delete 34,000 records, although I did not run into any governor limits. It seems that the execute() call is only receiving a few records at a time. Is there any way to coax it to process large groups of records?
Any help would be greatly appreciated.
global class MassDeleteCustomObject implements Database.Batchable<Sobject>
{
global final String query = 'select Id from <my custom object>';global Database.QueryLocator start(Database.BatchableContext BC)
{
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Sobject> records)
{
delete records;}
global void finish(Database.BatchableContext BC)
{
}
}
Thanks for the reply.
Even at 200 that's still 170 specific delete calls. Sometimes the number of records to be deleted is around 200,000 so that would be 1,000 individual calls. Not very efficient, and even still the SOAP API calls at 200 per trip seem to run faster despite the expense of all the round trips!
Not very efficient? You just deleted tens of thousands of records with fewer than 20 lines of code! That's pretty darn efficient!
Try using dataloader, exporting all the IDs, and then using that file to delete all the records. If it's faster, then go for it, and don't worry about this being "slow."
Really, 40 minutes is fairly good; remember that Batch Apex is not a high-priority process on the platform. It was never meant to be time-critical. You're waiting for higher-priority things to happen.
If you want to be at the front of the line for CPU cycles, use dataloader or the SOAP API (as you have done).
I had a similar problem. I needed to delete 2 .5 million records. I identified some partioning criteria and then generated several different CSV files and ran the data loader on multiple machines.
Stuart
Bhaskar
Hi All,
here is how you can do faster deletion :
1. Once you get all the Records in CSV, remove all other details except the IDs.
2. Use dataloader with bulk API Option.
You can delete a million records in less than 4mins !
Thanks,
Prashanth