function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sudha#aSudha#a 

any one write test class scheduable below code

global class Schedule_SubscriptionCMRRRollup implements Schedulable{

    public static String CRON = '0 00 00 * * ?';  //Every Day at Midnight 

    global static String scheduleMe() {
        Schedule_SubscriptionCMRRRollup SC = new Schedule_SubscriptionCMRRRollup(); 
        return System.schedule('Subscription CMRR Rollup Job', CRON, SC);
    }

    global void execute(SchedulableContext sc) {

        Batch_SubscriptionCMRRRollup batch = new Batch_SubscriptionCMRRRollup ();// create Object in Batch class//
        Database.executeBatch(batch,50);           
    }
}
VineetKumarVineetKumar
Test class would look something like this.

@isTest
private class TestSchedulableClass {
// Schedule the test job
String sch = '0 0 23 * * ?';
Schedule_SubscriptionCMRRRollup scheduleObject =  new Schedule_SubscriptionCMRRRollup();
String jobId = System.schedule('Schedule Test', sch, scheduleObject);
}
Amit Chaudhary 8Amit Chaudhary 8
Please check below post how to write test class for scheduler class
1) https://developer.salesforce.com/docs/atlas.en-us.apex_workbook.meta/apex_workbook/apex_scheduling_2.htm

Please try below test class
@isTest
private class Schedule_SubscriptionCMRRRollupTest 
{
   public static String CRON_EXP = '0 0 0 15 3 ? 2022';
   static testmethod void test() 
   {
      Test.startTest();

      String jobId = System.schedule('Schedule_SubscriptionCMRRRollup',  CRON_EXP, new Schedule_SubscriptionCMRRRollup());
         
      CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime  FROM CronTrigger WHERE id = :jobId];

      System.assertEquals(CRON_EXP,   ct.CronExpression);
      System.assertEquals(0, ct.TimesTriggered);

   }
}
Let us know if this will help you

Thanks
Amit Chaudhary
 
Sudha#aSudha#a
that is batch apex scheduab