Getting started with Job.apex
Hello World Job
Below is how we create a simple HelloWorldJob.
public class HelloWorldJob extends Func {
public HelloWorldJob() {
super(1);
}
public override Object exec(Object context) {
System.debug('Hello World');
return null;
}
}
We can directly use any Func as a Job executor.
Here is how we create a job.
Job j = new Job('helloworld', new HelloWorldJob());
And then we set when the job will execute.
j.everyDay().atHour(8);
Finally we schedule the job.
j.schedule();
We can combine all of these into:
new Job('helloworld', new HelloWorldJob())
.everyDay()
.atHour(8)
.schedule();