Wednesday, 29 November 2017

Salesforce - Schedulable test class

Add below statements in your test class to verify the test results


@isTest
static void test(){
// Schedule the test job
//Class runs every day at 1 PM.
      String jobId = System.schedule('testBasicScheduledApex','0 0 13 * * ?',     
         new TestScheduledApexFromTestMethod());

      // Get the information from the CronTrigger API object
      CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, 
         NextFireTime
         FROM CronTrigger WHERE id = :jobId];

      // Verify the expressions are the same
      System.assertEquals('0 0 13 * * ?', 
         ct.CronExpression);

      // Verify the job has not run 
      System.assertEquals(0, ct.TimesTriggered);
}

 

No comments:

Post a Comment