• Sidney Chow
  • NEWBIE
  • 5 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
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');
    }
}
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');
    }
}
hi guys,
help me out in using standard controllers in vf trailhead getting a error of
Challenge not yet complete... here's what's wrong: 
The page does not include a bound owner's email variable for the Contact record
cheers...