I have create batch class, i am calling in Developer Console but i want execute directly like when i schedule every monday. how to shedule this batch class global class contact_batch_update_Department implements
Database.Batchable<sobject>{
global String [] email = new String[] {'[email protected]'};
global Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator('SELECT id, Name, Department FROM Contact');
}
global void execute(Database.BatchableContext bc, List<sObject> scope){
List<Contact> conList = new List<Contact>();
for(sObject con : scope){
Contact newCon = (contact)con;
newCon.Department = 'IT Department';
conList.add(newCon);
}
if(conList.size()>0 && conList != null){
Database.update(conList);
}
}
global void finish(Database.BatchableContext bc){
AsyncApexJob a = [Select a.TotalJobItems, a.Status, a.NumberOfErrors, a.JobType, a.JobItemsProcessed, a.ExtendedStatus, a.CreatedById, a.CompletedDate From AsyncApexJob a WHERE id = :BC.getJobId()];
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(email);
mail.setReplyTo('[email protected]');
mail.setSenderDisplayName('Apex Batch Processing Module');
mail.setSubject('Batch Processing '+a.Status);
mail.setPlainTextBody('The Batch Apex job processed '+a.TotalJobItems+'\n batches with '+a.NumberOfErrors+' failures '+'\n Job Item processed are '+a.JobItemsProcessed);
Messaging.sendEmail(new Messaging.Singleemailmessage [] {mail});
}
}