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
Aryan JhaAryan Jha 

WHY TEST IS NOT WORKING

global class DailyLeadProcessor implements Schedulable {
    
    global void execute(SchedulableContext ctx) {
        
        
        List<Lead> leads = [SELECT ID, LeadSource FROM Lead where LeadSource = '' LIMIT 200];

        
        for (Lead lead : leads) {
            lead.LeadSource = 'Dreamforce';
        }

        
        update leads;
    }
test class
@isTest
private class DailyLeadProcessorTest {
    
    @isTest
    public static void testDailyLeadProcessor(){

      
        List<Lead> leads = new List<Lead>();
        for (Integer x = 0; x < 200; x++) {
            leads.add(new Lead(lastname='lead number ' + x, company='company number ' + x));
        }
        insert leads;

        Test.startTest();
        String jobId = System.schedule('DailyLeadProcessor', '0 0 12 * * ?', new DailyLeadProcessor());
        Test.stopTest();

   
        List<Lead> listResult = [SELECT ID, LeadSource FROM Lead where LeadSource = 'Dreamforce' LIMIT 200];
        System.assertEquals(200, listResult.size());

    }
}
Suraj Tripathi 47Suraj Tripathi 47
Hi,

Test class is working fine in my org. Please recheck your code and refresh the developer console.

Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi
CharuDuttCharuDutt
Hii Aryan Jha
Try Below Test Class
@isTest
public class DailyLeadProcessorTest {
     public static String CRON_EXP = '0 0 0 2 6 ? 2022';
@istest
    public Static void unitTest(){
        list<lead> lstLeads = new list<lead>();
        for(integer i=0;i<=200;i++){
            lead leads = new lead();
            leads.LastName = 'test ' + i;
            leads.Company = 'TRP';
            leads.LeadSource = '';
            lstleads.add(leads);
        }
        insert lstleads;
        	
        String jobId = System.schedule('Update LeadSource to DreamForce', CRON_EXP, new DailyLeadProcessor());
    }
}
Please Mark It As Best Answer if it Helps
Thank You!

 
ShivankurShivankur (Salesforce Developers) 
Hi Aryan,

I see the Test class is fully covered, when checked in my test developer org.

Please help adding more details about the issue you are facing with the code posted above.

Thanks.
Aryan JhaAryan Jha
The test does not working