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.
[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