Book Image

Learning Apex Programming

Book Image

Learning Apex Programming

Overview of this book

Table of Contents (17 chapters)
Learning Apex Programming
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Master control


If your scheduling needs are more complex, you need to be ultra-specific; you might not be able to easily use the Schedule Apex page. Let's say you need a process to run once a quarter or just once a year. Instead of trying to hack together some creative schedule, you can just use a CronTrigger. A CronTrigger represents a scheduled job and is similar to a cron job on UNIX systems. CronTriggers can be set with a very specific expression through the System.schedule() method. You can specify the schedule by seconds, minutes, hours, day of month, month, day of week, and year. There are options for using a range, intervals, and all possible numbers. Basically, if you can think of a schedule, you should be able to write a CronTrigger for it such as follows:

//Scheduling a Schedulable Apex Class
myScheduler cls = new myScheduler();
String cronExpression = '0 59 11 * * ?';  //Nightly at 11:59pm
String jobId = System.schedule('Job Name', cronExpression, cls);