8

I am trying to schedule a class to run every 15 minutes. I know we can set in salesforce for every hour, but is there a way to reduce the granularity to 10-15 minutes?

global class scheduledMerge implements Schedulable {
  global void execute(SchedulableContext SC) {
      ProcessTransactionLog p= new ProcessTransactionLog();
      p.ProcessTransaction();
   }
}
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Prady
  • 10,978
  • 39
  • 124
  • 176

2 Answers2

14

You can use this apex code snippet to schedule your job to run every 15 minutes.

System.schedule('Job1', '0 0 * * * ?', new scheduledMerge());
System.schedule('Job2', '0 15 * * * ?', new scheduledMerge());
System.schedule('Job3', '0 30 * * * ?', new scheduledMerge());
System.schedule('Job4', '0 45 * * * ?', new scheduledMerge());
fehays
  • 3,147
  • 1
  • 24
  • 43
Rajesh
  • 239
  • 2
  • 3
  • I'm pretty sure you can also use commas to delimit multiple values: `System.schedule('Job1', '0 0,15,30,45 * * * ?', new scheduledMerge());` – Matt Lacey Feb 04 '12 at 04:48
  • The first line of this answer will cause the job (theoretically) to execute every minute. The "cron-preferred" way to express "run every 15 minutes on the 15" would be '0 0/15 * * * ?'. – jkraybill Feb 05 '12 at 22:54
  • 3
    Matt, actually in Apex CRON you must specify Seconds and Minutes as Integers --- commas, stars, and dashes are only available for the other CRON components. So your '0,15,30,45' approach will not work. Also, a word of caution about following Rajesh's approach: you can only have 25 total Scheduled Apex Classes, and Rajesh's approach uses up 4 of them. But if you have this many jobs to spare, then this will work great. – zachelrath Jun 04 '12 at 21:20
  • 1
    System.schedule('Job1', '0 0 * * * ?', new scheduledMerge()); – Cray Kao Apr 05 '14 at 01:47
0
global class scheduledTest implements Schedulable {
    global void execute(SchedulableContext SC) {
        RecurringScheduleJob.startJob();   
        String day = string.valueOf(system.now().day());
        String month = string.valueOf(system.now().month());
        String hour = string.valueOf(system.now().hour());
        String minute = string.valueOf(system.now().minute() + 15);
        String second = string.valueOf(system.now().second());
        String year = string.valueOf(system.now().year());

        String strJobName = 'Job-' + second + '_' + minute + '_' + hour + '_' + day + '_' + month + '_' + year;
        String strSchedule = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?' + ' ' + year;
        System.schedule(strJobName, strSchedule, new scheduledTest());
    } 
}
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
  • 2
    Define a variable called 'now' and use addMinutes(Integer) method will be accurate. Datetime now = System.now(); Datetime nextE = now.addMinutes(10); – Cray Kao Apr 05 '14 at 01:45
  • this will run every 15 minutes even when i set the apex schedule to 1 hour? – sfdclearner Aug 12 '16 at 02:49