You need to sign in to do that
Don't have an account?
Kunal Purohit 4
I want to schedule my batch apex after 5 minutes. I have tried using cron,but not working... plz help
public class StatusPublished implements database.Batchable<sobject>,Schedulable{ public void execute(Schedulablecontext sc) { string cron='0 2 * * * ?*'; StatusPublished sp =new StatusPublished(); system.schedule('updatepaper', cron, sp); //database.executeBatch(sp); } public database.QueryLocator start(database.BatchableContext bc) { string query='select id,Name,Status__c from Research_Paper__c'; return database.getQueryLocator(query); } public void execute(database.BatchableContext bc,list<Account> acc) { List<Research_Paper__c> rlist=new list<Research_Paper__c>(); for(Research_Paper__c rp: rlist) { if(rp.Status__c=='Paper registration Complete') { rp.Status__c='Published'; rlist.add(rp); } } update rlist; } public void finish(database.BatchableContext bc) { }
public void execute(Schedulablecontext sc)
{
DataBase.executeBatch(new StatusPublished());
}
You can test this by running the following script in developer console anoymous window.
DataBase.executeBatch(new StatusPublished());
You can use this cron expression to schedule batch after every 5 minutes: 0 0/5 * 1/1 * ? *
Please use the below link to get the cron expression as per your requiremnet:
http://www.cronmaker.com/?1
Let me know if this works for you.
Thanks,
Abhishek Bansal.