Skip to content

Instantly share code, notes, and snippets.

@mannharleen
Created November 3, 2016 15:00
Show Gist options
  • Save mannharleen/78981a4ee4478dc4f950d7914bcd53f7 to your computer and use it in GitHub Desktop.
Save mannharleen/78981a4ee4478dc4f950d7914bcd53f7 to your computer and use it in GitHub Desktop.
Salesforce trailhead - Asynchronous Apex Scheduling Jobs Using the Apex Scheduler
public class DailyLeadProcessor implements schedulable{
public void execute(schedulableContext sc) {
List<lead> l_lst_new = new List<lead>();
List<lead> l_lst = new List<lead>([select id, leadsource from lead where leadsource = null]);
for(lead l : l_lst) {
l.leadsource = 'Dreamforce';
l_lst_new.add(l);
}
update l_lst_new;
}
}
@isTest
public class DailyLeadProcessorTest {
@isTest
public static void testing() {
List<lead> l_lst = new List<lead>();
for(Integer i=0;i<200;i++) {
lead l = new lead();
l.lastname = 'lastname'+i;
l.Company = 'company'+i;
l_lst.add(l);
}
insert l_lst;
Test.startTest();
DailyLeadProcessor dlp = new DailyLeadProcessor ();
String jobId = System.Schedule('dailyleadprocessing','0 0 0 1 12 ? 2016',dlp);
Test.stopTest();
List<lead> l_lst_chk = new List<lead>([select id,leadsource from lead where leadsource != 'Dreamforce']);
System.assertequals(0,l_lst_chk.size());
}
}
@DAnnapareddy
Copy link

Please change 2016 line 18 to * wild card

@kristinemaimai
Copy link

thank you so much!
i only missed this part "List l_lst_chk = new List([select id,leadsource from lead where leadsource != 'Dreamforce']);" to have my 100% code coverage.

@muddurthi
Copy link

In daily lead processor is not complete 100% coverage of code please send me the 100% code coverage

@areefabanu
Copy link

thank you so muchhhhh :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment