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
guptach45guptach45 

i need to write a test class for schedular class. Below is the schedular class----

Global class CSTeamCountryCaseUpdateSchedular implements Schedulable {
   Global void execute(SchedulableContext sc){
       
        CSTeamCountryCaseUpdateBatch batchClassInstance= new CSTeamCountryCaseUpdateBatch();
        Database.executeBatch(batchClassInstance);
       
    }
}
Best Answer chosen by guptach45
ANUTEJANUTEJ (Salesforce Developers) 
Hi Sakshi,

Can you try checking if the below code in https://developer.salesforce.com/forums/?id=906F00000008yhmIAA works?
 
public static testMethod void testschedule() {

Test.StartTest();
CSTeamCountryCaseUpdateSchedular sh1 = new CSTeamCountryCaseUpdateSchedular ();

String sch = '0 0 23 * * ?'; 
system.schedule('Test Territory Check', sch, sh1); 
Test.stopTest(); }
Aditionally you could have a look at https://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex/async_apex_scheduled for reference.

In case if this came handy can you please choose this as best answer so that it can be used for future reference by others.

Regards,
Anutej

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Sakshi,

Can you try checking if the below code in https://developer.salesforce.com/forums/?id=906F00000008yhmIAA works?
 
public static testMethod void testschedule() {

Test.StartTest();
CSTeamCountryCaseUpdateSchedular sh1 = new CSTeamCountryCaseUpdateSchedular ();

String sch = '0 0 23 * * ?'; 
system.schedule('Test Territory Check', sch, sh1); 
Test.stopTest(); }
Aditionally you could have a look at https://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex/async_apex_scheduled for reference.

In case if this came handy can you please choose this as best answer so that it can be used for future reference by others.

Regards,
Anutej
This was selected as the best answer
guptach45guptach45
It works. Thanks a lot.
ANUTEJANUTEJ (Salesforce Developers) 
Glad to know I was able to help Sakshi :)