Advertisement
Guest User

Untitled

a guest
May 4th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.47 KB | None | 0 0
  1. global class leadToBoerseAfter24H implements Schedulable{
  2. // Execute method
  3. global void execute(SchedulableContext SC) {
  4. // Code to be executed when the schedule class wakes up
  5. for(List<Lead> leads:[SELECT FirstName, LastName, Phone, MobilePhone, PostalCode, City, Street, Email, CreatedDate FROM Lead WHERE CreatedDate < YESTERDAY AND Email != null AND Status = 'Offen' AND (Lead_Status__c = null OR Lead_Status__c = 'Telefonisch nicht erreicht') AND (LeadSource = 'FWS Lead' OR LeadSource = 'AdressButler' OR LeadSource = 'WH Landingpage')]){
  6. List<lb_Leads__c> nL = new List<lb_Leads__c>();
  7. for(Lead l : leads){
  8. lb_Leads__c newL = new lb_Leads__c();
  9. newL.Vorname__c = l.FirstName;
  10. newL.Nachname__c = l.LastName;
  11. newL.Telefon__c = l.Phone;
  12. newL.Erstellt_datum__c = date.today();
  13. newL.Auktionsstart__c = date.today();
  14. newL.Anfangspreis__c = 120;
  15. newL.Status__c = 'active';
  16. newL.Stadt__c = l.City;
  17. if(l.PostalCode != null)
  18. newL.PLZ__c = l.PostalCode;
  19. else
  20. newL.PLZ__c = 'Keine Angabe';
  21. newL.Stra_e__c = l.Street;
  22. newL.Email__c = l.Email;
  23. newL.Mobiltelefon__c = l.MobilePhone;
  24. newL.Beschreibung__c = 'Pflegeimmobilie als Kapitalanlage';
  25. nL.add(newL);
  26. }
  27. if(!nL.isEmpty()){
  28. insert nL;
  29. delete leads;
  30. }
  31. }
  32. }
  33. }
  34.  
  35. @istest
  36. class TestLeadToBoerse {
  37.  
  38. static testmethod void test() {
  39. Lead l = (Lead) Json.deserialize('{"Company":"foo", "LastName":"bar",' +
  40. '"Email":"foo@bar.com",' +
  41. '"CreatedDate": "2015-04-04T17:54:26.000+0000",' +
  42. '"Status": "Offen", ' +
  43. '"LeadSource": "WH Landingpage",' +
  44. '"Lead_Status__c": "Telefonisch nicht erreicht",' +
  45. '"PostalCode": "33333", ' +
  46. '"FirstName": "Test",' +
  47. '"Gesch_ftsbeziehung__c": "Interessent",' +
  48. '"Maklerbetreuer_Wirtschaftshaus__c" : "Lars Wagner"}',
  49. Lead.class);
  50. insert l;
  51. String lName = l.FirstName;
  52. System.assertEquals(lName,
  53. [SELECT id, FirstName FROM Lead WHERE id = :l.id].FirstName);
  54. Test.startTest();
  55.  
  56.  
  57. // Schedule the test job
  58. String jobId = System.schedule('testBasicScheduledApex',
  59. '0 0 0 3 9 ? 2015',
  60. new LeadToBoerseAfter24H());
  61.  
  62. // Get the information from the CronTrigger API object
  63. CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered,
  64. NextFireTime
  65. FROM CronTrigger WHERE id = :jobId];
  66.  
  67. // Verify the expressions are the same
  68. System.assertEquals('0 0 0 3 9 ? 2015',
  69. ct.CronExpression);
  70.  
  71. // Verify the job has not run
  72. System.assertEquals(0, ct.TimesTriggered);
  73.  
  74. // Verify the next time the job will run
  75. System.assertEquals('2015-09-03 00:00:00',
  76. String.valueOf(ct.NextFireTime));
  77.  
  78. Test.stopTest();
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement