0

A followup to the issue I was having yesterday, so I've successfully created a schedule job to delete AS records every hour.

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){
    }


}

global class deleteaccountsharebatch implements Schedulable {



    global void execute(SchedulableContext SC)
    {
        string str='select id from AccountShare where lastmodifiedbyid =\'0050P000007Kfy2\' limit 5000';
        sharedeletebatch bdt=new sharedeletebatch(str);
        Database.executeBatch(bdt);
        system.debug(bdt);      
    }



}

then I run this in anonymous window.

 deleteaccountsharebatch m = new deleteaccountsharebatch();
String sch = '0 0 * * * ?';
String jobID = system.schedule('Hourly Job', sch, m);

The problem I'm having is that it keeps giving me "[REQUEST_RUNNING_TOO_LONG] Your request was running for too long, and has been stopped." error no matter how small I make the limit of the query.

So is that even the issue? Is there any other option or approach to mass delete a bunch of records on a schedule? I had no success with data loader either, similar 'been 10 min time out' error.

2
  • Please add the additional detail to your original question. I do not believe that the question at hand here is any different that the original (other than batch vs bulk api), if I am wrong then please leave a comment
    – Eric
    Mar 23, 2017 at 16:29
  • Additionally, I would suggest you may need to open a case with SF. You should be able to use [Select Id From {Whatever}] in a batch start without issue. Thats the whole point of a batch. If you cannot do that query and are under 50M records, IMHO it is a platform bug. Did you try removing the filter and evaluating in the batch execute for the last modifiedbyid. Not ideal I know but good for a test
    – Eric
    Mar 23, 2017 at 16:32

0

Browse other questions tagged .