global class DailyLeadProcessor implements Schedulable {
global void execute(SchedulableContext ctx){
List<Lead>leadstoupdate = new List<Lead>();
List<Lead>leads = [Select id from lead where Leadsource = NULL Limit 200];
for(Lead l : leads){
l.LeadSource= 'Dreamforce';
leadstoupdate.add(l);
}
update leadstoupdate;
}
}
--------------------------------------------------------------------------------------------------------------------------------------------------
@isTest
public class DailyLeadProcessorTest {
public static String CRON_EXP = '0 0 0 15 3 ? 2022';
static testmethod void testScheduledjob(){
List<Lead> leads = new List<lead>();
for (integer i=0; i<200; i++){
lead l = new lead(
FirstName = 'first '+ i,
LastName = 'LastName',
Company = 'The Inc'
);
leads.add(l);
}
insert leads;
Test.startTest();
String jobId = System.schedule('ScheduledApexTest', CRON_EXP, new DailyLeadProcessor());
Test.stopTest();
List<Lead> checkleads = new List<Lead>();
checkLeads =[Select Id From Lead Where LeadSource = 'Dreamforce' and Company = 'The Inc'];
System.assertEquals(200 , checkleads.size(), 'Leads were not created');
}
}
--------------------------------------------------------------------------------------------------------------------------------------------
why its showing Error (System.AsyncException: Based on configured schedule, the given trigger 'SCHEDULED_APEX_JOB_TYPE.000000000000000' will never fire.) for Test Class
You should use your CRON_EXP of future date so it can schedule your class like below.
public static String CRON_EXP = '0 0 0 31 5 ? 2023';