How to Run a Scheduled Job Every 15 Minutes?

Question:
Salesforce’s built-in GUI for scheduling jobs does not allow setting an interval shorter than one day. However, I need to run a scheduled job every 15 minutes. How can I achieve this in Apex?
CRS Info Solutions offers industry-leading Salesforce training in Singapore with real-time projects, Salesforce training certification guidance, interview coaching, and a practical approach to ensure you’re job-ready.
Answer:
Since the Salesforce UI does not support scheduling jobs more frequently than once per day, we can achieve this using Apex code. The best approach is to programmatically create multiple scheduled jobs at different time intervals within an hour.
The following Apex script dynamically schedules a job to run at every nth minute within an hour. You only need to specify the class name and the frequency in minutes.
// Modify these two variables as needed
Integer everyNthMinute = 15;
String nameOfSchedulableClass = 'YourSchedulableClassNameHere';
Integer counter = 1;
for (Integer minute = 0; minute < 60; minute++) {
if (Math.mod(minute, everyNthMinute) == 0) {
String scheduleName = nameOfSchedulableClass + String.valueOf(counter);
String cronPattern = '0 ' + String.valueOf(minute) + ' * * * ?';
System.schedule(scheduleName, cronPattern, (Schedulable) Type.forName(nameOfSchedulableClass).newInstance());
counter++;
}
}
Explanation:
This Apex code dynamically schedules a job to run at regular intervals (e.g., every 15 minutes) within an hour by iterating through all 60 minutes and scheduling instances of a specified class whenever the minute value is a multiple of everyNthMinute
. It constructs a unique schedule name and a cron expression for each scheduled instance, then uses System.schedule
to execute the job at the defined times.
This script creates scheduled jobs at intervals of 15 minutes (or any other frequency set in everyNthMinute
). The cronPattern
ensures that the job runs at the specified minute of every hour.
Another alternative is to use a chained scheduling approach, where a scheduled job schedules itself to run again after a specified interval. However, this method can be less reliable due to governor limits and execution delays.
Summing Up:
To schedule a job every 15 minutes in Salesforce, the platform’s cron expressions require scheduling multiple jobs due to restrictions on using comma-separated lists for minutes. You can set up four separate jobs to run at the 0th, 15th, 30th, and 45th minutes of each hour, effectively achieving the 15-minute interval. This method utilizes the System.schedule
method in Apex, where each job triggers the same class but at different times. For more flexibility, batch jobs can also be scheduled within the finish()
method to chain subsequent executions.
Empower Your Career with Salesforce Training in Singapore
Elevate your professional journey with CRS Info Solutions’ top-rated Salesforce training in Singapore, crafted to provide the skills and expertise required to excel in the ever-evolving Salesforce ecosystem. Our industry-focused courses span Salesforce Admin, Developer, and AI modules, blending in-depth theoretical knowledge with hands-on experience through practical, real-world projects. Whether you’re new to Salesforce or a seasoned professional, our well-structured program ensures you master the tools and techniques needed to stand out.
With a strong emphasis on practical application, Salesforce training in Singapore we offer personalized mentorship, detailed study resources, and expert-led certification preparation to fully equip you for success in interviews and beyond. Gain the confidence and skills to thrive in your Salesforce career.
Don’t wait—join our free demo class today and take the first step toward a rewarding future! Enroll now for a free demo!