You need to sign in to do that
Don't have an account?
Sidney Chow
Schedule Jobs Using the Apex Scheduler challenge
I was working the Schedule Jobs Using Apex Scheduler challenge. While I was able to solve the challenge by keeping only the System.schedule line and removing the rest under test(), I am curious on why, with the code below, it's giving me "variable does not exist: leads" on the Map line. Why isn't it recognizing the leads variable? Thanks!
@isTest
private class DailyLeadProcessorTest {
public static string CRON_D = '0 0 0 15 3 ? 2022';
@testSetup
static void setup() {
List<Lead> leads = new List<Lead>();
for (Integer i=0; i<200; i++) {
leads.add(new Lead(lastname='Last'+i, firstname='First', company='Company'));
}
insert leads;
System.debug('Done inserting leads ' + leads);
}
@isTest
static void test() {
Map<Id, Lead> leadMap = new Map<Id, Lead>(leads);
List<Id> leadIds = new List<Id>(leadMap.keySet());
Test.startTest();
String jobId = System.schedule('ScheduleApex Test', CRON_D, new DailyLeadProcessor());
List<Task> lt = [select Id from task where whatid in :leadids];
System.assertequals(0, lt.size(), 'Tasks exist before job has run');
Test.stopTest();
lt = [select id from task where whatid in :leadids];
system.assertequals(leadids.size(), lt.size(),'Tasks were not created');
}
}
@isTest
private class DailyLeadProcessorTest {
public static string CRON_D = '0 0 0 15 3 ? 2022';
@testSetup
static void setup() {
List<Lead> leads = new List<Lead>();
for (Integer i=0; i<200; i++) {
leads.add(new Lead(lastname='Last'+i, firstname='First', company='Company'));
}
insert leads;
System.debug('Done inserting leads ' + leads);
}
@isTest
static void test() {
Map<Id, Lead> leadMap = new Map<Id, Lead>(leads);
List<Id> leadIds = new List<Id>(leadMap.keySet());
Test.startTest();
String jobId = System.schedule('ScheduleApex Test', CRON_D, new DailyLeadProcessor());
List<Task> lt = [select Id from task where whatid in :leadids];
System.assertequals(0, lt.size(), 'Tasks exist before job has run');
Test.stopTest();
lt = [select id from task where whatid in :leadids];
system.assertequals(leadids.size(), lt.size(),'Tasks were not created');
}
}
Please note that Questions about how to pass Trailhead challenges are not on topic, because these challenges are intended to be independent demonstrations of your abilities.
Trailhead Help (https://trailhead.salesforce.com/en/help?support=home)can provide assistance for situations where Trailhead does not appear to be functioning correctly. You can reach out to them if this is the case.
Please close the thread by selected as Best Answer so that we can keep our community clean
Regards,
Salesforce Support.