Schedule Batch Apex For Every Hour
Batch Class:
global class accountBatch implements Database.Batchable<sobject> { global Database.QueryLocator start(Database.BatchableContext bc){ String query = 'SELECT Id, Name FROM Account'; return Database.getQueryLocator(query); } global void execute(Database.BatchableContext bc, List<account> scope) { for(Account a : scope) { a.Name = a.Name + 'Updated'; } update scope; } global void finish(Database.BatchableContext bc) { } }
Scheduled Class:
global class accountBatchSchedule implements Schedulable{ global void execute(SchedulableContext sc) { //invoke the batch class Database.executeBatch(new accountBatch()); } }
Execute below code from anonymous window in developer console. This will scheduled the job to run in every hour starting from 12:00 AM.
accountBatchSchedule sc = new accountBatchSchedule(); //Define cron expression String cronExp = '0 0 * * * ?'; String jobID = System.schedule('Update Account', cronExp, sc);