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
Stephen E 4Stephen E 4 

[2018] How to schedule an Apex job to run every 10 minutes?

We replicate tickets/data from external APIs and would like if we could create tickets every 10 minutes. Is that possible with scheduled apex? I have been getting a lot of conflicting answers when googling (and a lot of answers are very old, dating back to 2011.)

Thank you!
Raj VakatiRaj Vakati
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() + 10);
        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, 'Class Name');

Please refer this link 

https://developer.salesforce.com/forums/?id=906F00000008yFvIAI
Stephen E 4Stephen E 4
Thank you very much for the quick response! However, when I run this, I get this error: 

"Method does not exist or incorrect signature: void CronScheduleTest() from the type anon"


I am executing this from the "Execute Anonymous Apex" screen.

Here is all my code:
 
global class CronScheduleTest implements Schedulable {
    
    global void execute(SchedulableContext SC) {
      Case cc = new Case();
      cc.Subject = 'this is my schedule case';
      insert cc;
   }

}


 
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() + 10);
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, CronScheduleTest());

 
Raj VakatiRaj Vakati
Here is the code
 
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() + 10);
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 CronScheduleTest());

 
Stephen E 4Stephen E 4
Thanks! I was missing the "New" however, we have another issue. It scheduled a job, and it ran 10 minutes later, however, it only ran once, and now its saying its not going to run again. How can we schedule this to run every 10 minutes forever? rather than just 10 minutes one time?