function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Waqar Hussain SFWaqar Hussain SF 

how to run batch class every hour? here is my schedulable class. my class doesn't run after every hour. I have to run through the developer console.

global with sharing class SchedularForBatchApex implements Schedulable {
        
        global void execute(SchedulableContext sc) {
            myBatchClass d = new myBatchClass();
              database.executebatch(d, 10);
        }
        
         Public static void SchedulerMethod(){
             SchedularForBatchApex s = new SchedularForBatchApex();
             string con_exp= '0 0 * * * ?';
             System.schedule('myBatchClass', con_exp, s);
         }
               
 }
Best Answer chosen by Waqar Hussain SF
Waqar Hussain SFWaqar Hussain SF
 Hi Mr Salesforce...
 String con_exp = '0 0 1 * * ?';
 I think this expression run everyday at 1 A.M.
Am I right or wrong?

All Answers

Jigar.LakhaniJigar.Lakhani
Hello,

It looks like you have defined wrong expression for schedule at every one hour.
Correct:  '0 0 1 * * ?'

Replace "SchedulerMethod":
Public static void SchedulerMethod(){
	SchedularForBatchApex s = new SchedularForBatchApex();
	string con_exp= '0 0 1 * * ?';
	System.schedule('myBatchClass', con_exp, s);
}

Thanks & Cheers,
Jigar
Waqar Hussain SFWaqar Hussain SF
 Hi Mr Salesforce...
 String con_exp = '0 0 1 * * ?';
 I think this expression run everyday at 1 A.M.
Am I right or wrong?
This was selected as the best answer
Jigar.LakhaniJigar.Lakhani
Oh,...Yes, Sorry about that. You are correct.

But your expression is correct as per the, Second, Minute, Hour....(0 0 * * * ?);
Then I am not sure whay it is not wokring.

Can you try with - '0 59 * * * ?'. if it works.

Thanks & Cheers,
Jigar
sadasiva07sadasiva07

String s1='0 05 * * * ? 2014';
    System.schedule('<Nameof the schedule job>',s1,<u r object>);