Adding a Class that Implements the Schedulable Interface | Techila
single,single-post,postid-830,single-format-standard,ajax_updown_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,qode-content-sidebar-responsive,qode-theme-ver-9.4.2,bridge,wpb-js-composer js-comp-ver-4.12,vc_responsive

Adding a Class that Implements the Schedulable Interface

Adding a Class that Implements the Schedulable Interface

In this lesson, you’ll write a class that implements the Schedulable interface, which means it can be scheduled to run at a specified date and time.

1.       In the Developer Console, click File | New | Apex Class.

2.       For the class name, enter MySchedulableClass and click OK.

3.       Delete the auto-generated code and add the following.

global class MySchedulableClass implements Schedulable {

global void execute(SchedulableContext ctx) {

CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime

FROM CronTrigger WHERE Id = :ctx.getTriggerId()];



 Merchandise__c m = new Merchandise__c(

 Name='Scheduled Job Item',

  Description__c='Created by the scheduler',



 insert m;




1.       Click File | Save.

·   The declaration of the class contains an extra implements Schedulable at the end. This indicates that the class implements the Schedulable interface and must implement the only method that this interface contains, which is this execute method:


global void execute(SchedulableContext sc){}

·    The parameter of this method is a SchedulableContext object. It provides the getTriggerId method that returns the ID of the CronTrigger API object. After a class has been scheduled, a CronTrigger object is created that represents the scheduled job.

·       The CronTrigger object is queried to get additional information about the scheduled job. The Cron expression and the number of times the job has been run already is written to the debug log.

·         Finally, the execute method creates a merchandise record.


“Explore – Techila Global Services, A Salesforce development company”

Author: techila

No Comments

Post A Comment