Hi Mohit,
Cron expression for scheduling batch in Salesforce
Cron expression
Every 30 minutes – ‘0 30 * * * ?’
Every hourly – ‘0 0 * * * ?’
Every 5 min – ‘0 5 * * * ?’
Every 10 min – ‘0 10 * * * ?’
Every 15 min – ‘0 15 * * * ?’
Every 20 min – ‘0 20 * * * ?’
Every 25 min – ‘0 25 * * * ?’
Every 30 min – ‘0 30 * * * ?’
like upto 55 or 59 your wish
Note: If you schedule your batch for every 5 min ‘0 5 * * * ?’. It means it will run every hours 5th minute.
It will not run every 5 minutes
If you want to run for every 5 min then you need to schedule 12 times with different different cron expression like for 5 min, 10 min, 15min like upto 60 min..
but you can use below code to schedule your batch for every 5o minutes
global class SelfSchedule implements schedulable
{
global void execute( SchedulableContext SC )
{
// do whatever it is you want to do here
SelfSchedule.start();
// abort me and start again
System.abortJob( SC.getTriggerId() );
}
public static void start()
{
// start keepalive again in 5 mins
Datetime sysTime = System.now().addSeconds( 3000);
String chronExpression = ” + sysTime.second() + ‘ ‘ + sysTime.minute() + ‘ ‘ + sysTime.hour() + ‘ ‘ + sysTime.day() + ‘ ‘ + sysTime.month() + ‘ ? ‘ + sysTime.year();
System.schedule( ‘SelfSchedule ‘ + sysTime, chronExpression, new SelfSchedule() );
}
}
Hope it may Helps you
thanks