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
sfdc development hintssfdc development hints 

Hi can anyone please helpme to write a test class for the below code

global class ClsTargetedCalls_ExecuteBatch implements Schedulable
{
   global void execute(SchedulableContext sc) 
   {
        System.debug('Before Execution');
        ClsTargetedCalls objclsTargetedCalls = new ClsTargetedCalls(); 
        System.debug('After Execution');
        database.executebatch(objclsTargetedCalls);       
        
   }
}

Best Answer chosen by Admin (Salesforce Developers) 
vishal@forcevishal@force

Hello, 

 

@isTest
static void testScheduler()
{
Test.startTest();
String jobId = System.schedule('testTargetedCallsBatchSchedule',
'0 0 0 15 10 ? 2012',
new ClsTargetedCalls_ExecuteBatch());
Test.stopTest();
}

 

All Answers

UVUV

You will have to shcedule the schedulable class from the test class itself programmatically to cover the case.

Example is given over here-

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm

vishal@forcevishal@force

Hello, 

 

@isTest
static void testScheduler()
{
Test.startTest();
String jobId = System.schedule('testTargetedCallsBatchSchedule',
'0 0 0 15 10 ? 2012',
new ClsTargetedCalls_ExecuteBatch());
Test.stopTest();
}

 

This was selected as the best answer