+ Start a Discussion
niharnihar 

can anyone help how to schedule a batch for every two minutes

Hi All,
how to schedule batch class for  every 2 minuets

My Batch class :
global class InsertIterableBatch  implements database.Batchable<Slot__c> {
global Iterable<Slot__c> start (database.Batchablecontext bc){
        list<Slot__c> slotReclist = new list<Slot__c>(); 
        for(integer i=0;i<100;i++){
        Slot__c  slotRe = new Slot__c();
        slotre.RecordTypeId = '01228000000SxvX';
        slotRe.Duration__c = 1;
        slotRe.start_date_time__c = Datetime.newInstance(2018,5,1,15,0,0);
        slotRe.End_Date_Time__c =   Datetime.newInstance(2018,5,1,15,0,0);  
        slotRe.Max_No_Of_Students__c = 10;
        slotReclist.add(slotRe);
        }
        return slotReclist;
        }
global void execute (database.BatchableContext bc, list<Slot__c> slotreclist){
        insert slotReclist;
        }
global void finish (database.Batchablecontext bc){
        }
        }

how to schedule batch class for every 2 minuets
Best Answer chosen by nihar
bhanu_prakashbhanu_prakash
Hi Nihar,
Mark as best answer, If it resloves !!
Go to your developer console -> Open Execute Anonymous Window -> Copy and Paste Below code and click on execute button
System.schedule('Schedule Job Name 1',  '0 00 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 2',  '0 02 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 3',  '0 04 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 4',  '0 06 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 5',  '0 08 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 6',  '0 10 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 7',  '0 12 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 8',  '0 14 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 9',  '0 16 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 10', '0 18 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 11', '0 20 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 12', '0 22 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 13',  '0 24 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 14',  '0 26 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 15',  '0 28 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 16',  '0 30 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 17',  '0 32 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 18',  '0 34 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 19',  '0 36 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 20',  '0 38 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 21',  '0 40 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 22', '0 42 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 23', '0 44 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 24', '0 46 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 25',  '0 48 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 26',  '0 50 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 27',  '0 52 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 28',  '0 54 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 29',  '0 56 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 30',  '0 58 * * * ?', new InsertIterableBatch());

After this, if you want To check apex class in scheduled or not then:
Go to -> Setup -> Jobs -> Scheduled Jobs

Thanks, 
Bhanu Prakash
visit ForceLearn.com  (https://www.forcelearn.com)
 

All Answers

bhanu_prakashbhanu_prakash
Hi Nihar,
Mark as best answer, If it resloves !!
Go to your developer console -> Open Execute Anonymous Window -> Copy and Paste Below code and click on execute button
System.schedule('Schedule Job Name 1',  '0 00 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 2',  '0 02 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 3',  '0 04 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 4',  '0 06 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 5',  '0 08 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 6',  '0 10 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 7',  '0 12 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 8',  '0 14 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 9',  '0 16 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 10', '0 18 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 11', '0 20 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 12', '0 22 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 13',  '0 24 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 14',  '0 26 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 15',  '0 28 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 16',  '0 30 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 17',  '0 32 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 18',  '0 34 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 19',  '0 36 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 20',  '0 38 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 21',  '0 40 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 22', '0 42 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 23', '0 44 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 24', '0 46 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 25',  '0 48 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 26',  '0 50 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 27',  '0 52 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 28',  '0 54 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 29',  '0 56 * * * ?', new InsertIterableBatch());
System.schedule('Schedule Job Name 30',  '0 58 * * * ?', new InsertIterableBatch());

After this, if you want To check apex class in scheduled or not then:
Go to -> Setup -> Jobs -> Scheduled Jobs

Thanks, 
Bhanu Prakash
visit ForceLearn.com  (https://www.forcelearn.com)
 
This was selected as the best answer
Narender Singh(Nads)Narender Singh(Nads)
Hi nihar,

Try this:

String sch = '0 5 * * * ? ';// CRON expression for every five minutes
String jobID = System.schedule('Job name 1', sch, new InsertIterableBatch());

Let me know if it helps
Thanks
bhanu_prakashbhanu_prakash
Thanks Nihar, for update & chosing as best answer 😊 😊 😊 😊 

Thanks, 
Bhanu Prakash
visit ForceLearn.com  (https://www.forcelearn.com)