Just to add a touch more to Adrian's answer if I may, I'd like to give some context to this code that you've read:
scheduledMerge m = new scheduledMerge();
String sch = '20 30 8 10 2 ?';
String jobID = system.schedule('Merge Job', sch, m);
Specifically, what does
system.schedule('Merge Job', sch, m) do?
System.schedule is, as you've identified, a more complex method of scheduling a class and takes 3 parameters:
The first parameter is the name. This is used more as a description but at the time of execution, the name must be unique otherwise you'll get an error akin to the following:
Scheduled job 'MyScheduledJob' threw unhandled exception.
caused by: System.AsyncException: The Apex job named "MyScheduledJob'" is already scheduled for execution.
This may or may not be a good thing.
This is the string you set here:
String sch = '20 30 8 10 2 ?'; and is known as a "Cron Expression". This is constructed by:
- Day of Month
- Day of Week
- Year (Optional)
There's also some special characters, I'd highly recommend reading up on this documentation. Basically, this tells the scheduler how often it should run. Here's a table from that documentation that explains it a bit better:
0 0 13 * * ? Class runs every day at 1 PM.
0 0 22 ? * 6L Class runs the last Friday of every month at 10 PM.
0 0 10 ? * MON-FRI Class runs Monday through Friday at 10 AM.
0 0 20 * * ? 2010 Class runs every day at 8 PM during the year 2010.
The final parameter is the class itself that you want to execute! In this case, it's a class called