You need to sign in to do that
Don't have an account?
Sanu Verma
How to write CronJobDetails Test Class
Want to Write CronJobDetail Test class
public void abortCronJob(){ List<CronJobDetail> detailIds = new List<CronJobDetail>([Select Id From CronJobDetail where Name ='ScheduleBatchPaymentDaysPassed']); System.debug('++detailsIds++=='+detailIds); if(detailIds != null && detailIds.size() > 0){ Id detailId = detailIds[0].Id; List<CronTrigger> cronTriggerList = new List<CronTrigger>([SELECT Id from CronTrigger WHERE CronJobDetailId = :detailIds[0].Id]); if(cronTriggerList.size() > 0){ System.abortJob(cronTriggerList[0].Id); } } }
Please refer the below code. Hope it helps you.
@isTest
private class cornJobDetailTest {
@IsTest static void test()
{
String CRON_EXP = '0 0 0 15 3 ? *';
Test.startTest();
Id JobId = system.schedule('ScheduleBatchPaymentDaysPassed',CRON_EXP, //name of your schedule class for eg :- new schedulejobDetailclass());
CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered, NextFireTime FROM CronTrigger WHERE id = :jobId];
System.assertEquals(CRON_EXP, ct.CronExpression);
System.assertEquals(0, ct.TimesTriggered);
Test.stopTest();
}
}
Please select as best answer if it helps you.
Thank You,
Ajay Dubedi
can u plzz tell me why is it so...
Try this one.
@IsTest
private class cornJobDetailTest {
@IsTest static void test()
{
string cronex = '0 0 0/6 1/1 ? '; // you need to write a corn expression as required.
ScheduleBatchOpportunity schdel = new ScheduleBatchOpportunity(); // Here you need to write a schedulable class of yours and instatciate it like this.
Id JobId = system.schedule('Every 6 hrs of schedule',cronex, schdel); // here passs the object of above schedule class in place of "schdel".
Test.startTest();
//Here you need to instantiate your batch class.
BatchPaymentDaysPassed batchpayment = new BatchPaymentDaysPassed(); // I hope this is your batch class.
Test.stopTest();
}
}
Please select as best answer if it helps you.
Thank You,
Ajay Dubedi