[SalesForce] Easiest way to delete a million records

Been doing tests in sandbox in which I've created about a million accountshares that I need to get rid of for testing.

I'm trying data loader in bulk api mode to export than delete but I keep getting:

InvalidBatch : Failed to process query: QUERY_TIMEOUT: Your query request was running for too long. Trying again later.;

Not sure if I should be waiting longer? Any other options or dataloader configurations I should be looking at?

EDIT

I've been trying with batch apex jobs yet still having issues.

Script

string str='select id from AccountShare where lastmodifiedbyid =\'0050P000007Kfy2\' limit 10000';
sharedeletebatch bdt=new sharedeletebatch(str);
Database.executeBatch(bdt);
system.debug(bdt);

Batch

global class sharedeletebatch Implements Database.batchable<sobject>
{

     global final string query;
     global sharedeletebatch(string q){

          query=q;
     }

     global Database.QueryLocator start(Database.BatchableContext BC){

      return Database.getQueryLocator(query);
     }
     global  void execute(Database.BatchableContext BC,List<SObject> scope){
         delete scope;

    }
    global void finish(Database.BatchableContext BC){
    }


}

First error: [REQUEST_RUNNING_TOO_LONG] Your request was running for too long, and has been stopped.

Best Answer

As it was already mentioned in the comments section, it might have been a Salesforce issue which is no longer the case. Exporting that amount of data shouldn't throw a timeout.

Nevertheless, if you would like to stick to the Data Loader, consider modifying (increasing) the following values at Settings):

  • batch size (if Bulk API is enabled, the max value is 10000)
  • timeout
  • query request size (the max value is 2000)

But if there is a need to repeat the process, it will be much easier to get familiar with Batch Apex.

Usage example: What is best way to delete all records from any Dev org