Advertisement
Learnify_Rectify

Schedule Jobs Using the Apex Scheduler

Jun 23rd, 2024 (edited)
8,503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | Source Code | 0 0
  1. Schedule Jobs Using the Apex Scheduler from (module - Asynchronous Apex)
  2.  
  3. -------------------------------------------------
  4. SOURCE CODE1: DailyLeadProcessor
  5.  
  6. public class DailyLeadProcessor implements Schedulable {
  7. Public void execute(SchedulableContext SC){
  8. List<Lead> LeadObj=[SELECT Id from Lead where LeadSource=null limit 200];
  9. for(Lead l:LeadObj){
  10. l.LeadSource='Dreamforce';
  11. update l;
  12.      } }}
  13.     
  14. -------------------------------------------------
  15. SOURCE CODE1: DailyLeadProcessorTest
  16.  
  17. @isTest
  18. private class DailyLeadProcessorTest {
  19. static testMethod void testDailyLeadProcessor() {
  20. String CRON_EXP = '0 0 1 * * ?';
  21. List<Lead> lList = new List<Lead>();
  22. for (Integer i = 0; i < 200; i++) {
  23. lList.add(new Lead(LastName='Dreamforce'+i, Company='Test1 Inc.', Status='Open - Not Contacted'));
  24. }
  25. insert lList;
  26. Test.startTest();
  27. String jobId = System.schedule('DailyLeadProcessor', CRON_EXP, new DailyLeadProcessor()); 
  28. } }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement