You need to sign in to do that
Don't have an account?
![TheRealist TheRealist](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
How to make a Batch Apex run recursively?
Hi
How to make a batch apex run recursively ,i mean when ever we run a batch apex once it is finished ,it does not run again automatically,
so can someone help me about,how to run it continuously,
Below is my sample batch apex
public class BatchLeadDelete implements database.Batchable<sobject>
{
list<lead> llist=new list<lead>();
public string query='select id,name,Phone from lead';
public string flag='12345';
public database.querylocator start(database.BatchableContext bc){
return database.getQueryLocator(query);
}
public void execute(database.BatchableContext bc,list<lead> le){
for(lead l:le){
if(l.Phone==flag)
{
llist.add(l);
}
}
delete llist;
}
public void finish(database.BatchableContext bc){
}
}
calling the above class with below code
BatchLeadDelete l=new BatchLeadDelete();
database.executeBatch(l,50);
How to make a batch apex run recursively ,i mean when ever we run a batch apex once it is finished ,it does not run again automatically,
so can someone help me about,how to run it continuously,
Below is my sample batch apex
public class BatchLeadDelete implements database.Batchable<sobject>
{
list<lead> llist=new list<lead>();
public string query='select id,name,Phone from lead';
public string flag='12345';
public database.querylocator start(database.BatchableContext bc){
return database.getQueryLocator(query);
}
public void execute(database.BatchableContext bc,list<lead> le){
for(lead l:le){
if(l.Phone==flag)
{
llist.add(l);
}
}
delete llist;
}
public void finish(database.BatchableContext bc){
}
}
calling the above class with below code
BatchLeadDelete l=new BatchLeadDelete();
database.executeBatch(l,50);
Database.executeBatch(new BatchLeadDelete(), 50);
in the finish method of the batch process.
You might have to abort it from Setup > Monitoring > Apex jobs to stop executing further.