Skip to main content
How to Schedule a batch Apex using system.schdule with code not through UI and where to write it ,

Below is my sample code:

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

        

    }

 }

I called the above class with below code

BatchLeadDelete l=new BatchLeadDelete();

    database.executeBatch(l,50); 
5 risposte
  1. 9 giu 2015, 09:38
    Thanks  @justin_sfdc and @Amit Chaudhary 8...

    Hi justin_sfdc, how to schedule the job to run on

    Mondays of every week at 10 hr 15th min

     
0/9000