You need to sign in to do that
Don't have an account?
Swap s 9
Create an Apex class that uses Scheduled Apex to update Lead records (Trail Head Challenge)
Hi,
Below is the Schedule Class with Test Class:
Schedule Class:
global class DailyLeadProcessor implements Schedulable {
global void execute(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;
}
}
}
Test Class:
@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();
}
}
Below is the Schedule Class with Test Class:
Schedule Class:
global class DailyLeadProcessor implements Schedulable {
global void execute(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;
}
}
}
Test Class:
@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();
}
}
Try this : Test class :
Regards,
Ajay
Try below code in class it will be executed.