You need to sign in to do that
Don't have an account?
o2b
How to schedule jobs every 10 minutes
Current documents has no example on how to schedule apex jobs every 10 mins. I tried with unix cron job syntax style (like 0,10,20,30,40,50 slots), that doesn't work.
Any help would be appreciated.
Thanks
Below code will autometically schedule job for every 10 minutes. You just need to first time invoke this method.
All Answers
Try setting up 4 schedules; hourly at 00, hourly at 15, hourly at 30, hourly at 45.
You can have max 10 schedules per org.
You can schedule the Apex class every hour (max 10) but I don't see any option to schedule on a frequency less than hour.
Let's if you want to schedule a class e.g. myClass.somemethod() you coding the scheduler class provided myClass implements schedulable
global void execute(SchedulableContext SC) {
//Inside code for someMethod()
}
Once you have created the schedulable class you can simply go to App Setup--> Apex Classes and click schedule button to create a scheduled job.
The repeat the job more than once a day, create a new schedule for the same myClass.someMethod() . For example first schedule at 10:00 AM, next 11:00 AM , next 12:00 noon and so on.
I didn't see any option to schedule something like 11:10, 11:20:11:30 etc. I don't think this is even possible as of today.
In order to schedule a job to run every 10 minutes you need to schedule 6 different jobs, since with spring 10' release, the min interval in which a job can run is every hour. You should run this code from the system log:
YourScheduleClass c = new YourScheduleClass();
String sch = '0 0 * * * ?';
System.schedule('Schedule Job1', sch, c);
YourScheduleClass c = new YourScheduleClass();
String sch = '0 10 * * * ?';
System.schedule('Schedule Job2', sch, c);
YourScheduleClass c = new YourScheduleClass();
String sch = '0 20 * * * ?';
System.schedule('Schedule Job3', sch, c);
YourScheduleClass c = new YourScheduleClass();
String sch = '0 30 * * * ?';
System.schedule('Schedule Job4', sch, c);
YourScheduleClass c = new YourScheduleClass();
String sch = '0 40 * * * ?';
System.schedule('Schedule Job5', sch, c);
YourScheduleClass c = new YourScheduleClass();
String sch = '0 50 * * * ?';
System.schedule('Schedule Job6', sch, c);
Check my first and recent post mate:
http://community.salesforce.com/t5/Apex-Code-Development/How-to-create-a-Schedule-Job-which-runs-after-specific-interval/m-p/178565
Mail me at ssaini@astadia.com if need any help on this.
Thanks,
Sam
I can scheduled every 10 min by helping this code but now problem is after 10 job it will give limit error.
how can i sheduled more then 10 job or after completing delete this job so we can sheduled new job.
Thanks
Yuvraj
Is there anyway to KILL a job from Apex code?
Yeah, use getTriggerId() from the SchedulableContext reference variable. It will return an Id wich you can pass to System.abortJob()
Below code will autometically schedule job for every 10 minutes. You just need to first time invoke this method.
datetime dt=system.now().minute() >54 ? system.now().addMinutes(6) : system.now();
//RecurringScheduleJob.startJob();
String day = string.valueOf(dt.day());
String month = string.valueOf(dt.month());
String hour = string.valueOf(dt.hour());
String minute = string.valueOf(dt.minute() + 5);
String second = string.valueOf(dt.second());
String year = string.valueOf(dt.year());
String strJobName = 'Job-' + second + '_' + minute + '_' + hour + '_' + day + '_' + month + '_' + year;
String strSchedule = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
system.debug(strSchedule+'Time stamp');
Schedule manager on AppExchange - https://appexchange.salesforce.com/listingDetail?listingId=a0N3A00000DqCmYUAV. Can execute your schedule periodically, like you want. You can configure run time every 5 minutes, every hour, once a month, etc.
The most appropriate solution for this I believe would be to have separate schedulers.
for example if i am executing the scheduler every 1 min and when the system.now().minute() + 1= 60 then scheduler will be stop. we have only one changes
DateTime now = System.Now().addMinutes(1);//you can add any minute here and you have not to check the condtion also that it become 60 or not
String day = string.valueOf(now.day());
String month = string.valueOf(now.month());
String hour = string.valueOf(now.hour());
String minute = string.valueOf(now.minute());
String second = string.valueOf(now.second());
String year = string.valueOf(now.year());
String cronExpression = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
System.schedule(strJobName, cronExpression, new scheduledTest());
hope it will help