-2

I am working on the Schedule Jobs Using the Apex Scheduler module, and I am getting the below error:

Method does not exist or incorrect signature: void schedule(String, String, DailyLeadProcessor) from the type System

DailyLeadProcessor

global class DailyLeadProcessor implements Queueable{

    global void execute(System.QueueableContext ctx){
        List<Lead> lList = [Select Id, LeadSource from Lead where LeadSource = null limit 200];
        list<lead> led = new list<lead>();
        if(!lList.isEmpty()) {
            for(Lead l: lList) {
                l.LeadSource = 'Dreamforce';
                led.add(l);
            }
            update led;
        }
    }
}

DailyLeadProcessorTest

@isTest
public class DailyLeadProcessorTest {

    static testMethod void testMethod1(){
        Test.startTest();
        List<Lead> lstLead = new List<Lead>();
        for(Integer i = 0; i<200;i++){
            Lead led = new Lead();
            led.FirstName ='FirstName';
            led.LastName ='LastName'+i;
            led.Company ='demo'+i;
            lstLead.add(led);
        }
        insert lstLead;

        DailyLeadProcessor ab = new DailyLeadProcessor();
        String jobId = System.schedule('jobName', '0 5 * * * ?',ab);

        Test.stopTest();
    }
}

enter image description here

2 Answers 2

5

You are facing this issue because you are calling System.schedule() method by passing a class instance which has implemented the Queuable interface, whereas it expects a parameter of the class instance which has implemented the Schedulable interface.

DailyLeadProcessor ab = new DailyLeadProcessor();
String jobId = System.schedule('jobName', '0 5 * * * ?',ab);

Please modify your original class and implement Schedulable interface instead of the Queuable.

global class DailyLeadProcessor implements Schedulable{

global void execute(System.SchedulableContext ctx){
    List<Lead> lList = [Select Id, LeadSource from Lead where LeadSource = null limit 200];
    list<lead> led = new list<lead>();
    if(!lList.isEmpty()) {
        for(Lead l: lList) {
            l.LeadSource = 'Dreamforce';
            led.add(l);
        }
        update led;
    }
}
}
2

The trailhead asks you to implement Schedulable interface and not Queueable.

Change class definition to this:

global class DailyLeadProcessor implements Schedulable {

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .