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
AG_SFDCAG_SFDC 

Test class for a Schedular Class

Hello,

Any samples on how to write a test class for a Schedular Class.

Thanks in Advance!!
Best Answer chosen by AG_SFDC
Mahesh DMahesh D
Hi,

Please follow the below example to write a Test Class for Scheduler:
 
@isTest
private class ScheduledClassTest {

    public static String CRON_EXP = '0 0 1 * * ?';
	@isTest
    static void testApexScheduledClass() {
        
		// Create the required records Like Accounts
		Account acc = new Account();
		acc.Name = 'Test Acc';
		insert acc;
		
		String jobId = System.schedule('ScheduledClass', CRON_EXP, new ScheduledClass());
         
        CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];

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

Regards,
Mahesh