+ Start a Discussion
TheRealistTheRealist 

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);  
Krishna SambarajuKrishna Sambaraju
Try adding
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.
omm ommomm omm
write a schedule class which run for every one minuite . so the class will run recursively