Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global class leadToBoerseAfter24H implements Schedulable{
- // Execute method
- global void execute(SchedulableContext SC) {
- // Code to be executed when the schedule class wakes up
- 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')]){
- List<lb_Leads__c> nL = new List<lb_Leads__c>();
- for(Lead l : leads){
- lb_Leads__c newL = new lb_Leads__c();
- newL.Vorname__c = l.FirstName;
- newL.Nachname__c = l.LastName;
- newL.Telefon__c = l.Phone;
- newL.Erstellt_datum__c = date.today();
- newL.Auktionsstart__c = date.today();
- newL.Anfangspreis__c = 120;
- newL.Status__c = 'active';
- newL.Stadt__c = l.City;
- if(l.PostalCode != null)
- newL.PLZ__c = l.PostalCode;
- else
- newL.PLZ__c = 'Keine Angabe';
- newL.Stra_e__c = l.Street;
- newL.Email__c = l.Email;
- newL.Mobiltelefon__c = l.MobilePhone;
- newL.Beschreibung__c = 'Pflegeimmobilie als Kapitalanlage';
- nL.add(newL);
- }
- if(!nL.isEmpty()){
- insert nL;
- delete leads;
- }
- }
- }
- }
- @istest
- class TestLeadToBoerse {
- static testmethod void test() {
- Lead l = (Lead) Json.deserialize('{"Company":"foo", "LastName":"bar",' +
- '"Email":"foo@bar.com",' +
- '"CreatedDate": "2015-04-04T17:54:26.000+0000",' +
- '"Status": "Offen", ' +
- '"LeadSource": "WH Landingpage",' +
- '"Lead_Status__c": "Telefonisch nicht erreicht",' +
- '"PostalCode": "33333", ' +
- '"FirstName": "Test",' +
- '"Gesch_ftsbeziehung__c": "Interessent",' +
- '"Maklerbetreuer_Wirtschaftshaus__c" : "Lars Wagner"}',
- Lead.class);
- insert l;
- String lName = l.FirstName;
- System.assertEquals(lName,
- [SELECT id, FirstName FROM Lead WHERE id = :l.id].FirstName);
- Test.startTest();
- // Schedule the test job
- String jobId = System.schedule('testBasicScheduledApex',
- '0 0 0 3 9 ? 2015',
- new LeadToBoerseAfter24H());
- // Get the information from the CronTrigger API object
- CronTrigger ct = [SELECT Id, CronExpression, TimesTriggered,
- NextFireTime
- FROM CronTrigger WHERE id = :jobId];
- // Verify the expressions are the same
- System.assertEquals('0 0 0 3 9 ? 2015',
- ct.CronExpression);
- // Verify the job has not run
- System.assertEquals(0, ct.TimesTriggered);
- // Verify the next time the job will run
- System.assertEquals('2015-09-03 00:00:00',
- String.valueOf(ct.NextFireTime));
- Test.stopTest();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement