/ Published in: Java
This is the test class for the LeadReassignment class.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
@isTest private class LeadReassignOnActivityHistoryTest { static testMethod void TestLeadReassign() { // User Id's for the two sales managers. Test.StartTest(); // Create 100 Leads and assign them to the sales manager of the opposite location. for (integer i=0; i<100; i++) { Lead l = new Lead(FirstName='LocationA', LastName='Lead'+ i, Location__c = 'Location B', Company = 'NA', OwnerId = bId); leadList.add(l); } //close for-loop // Create 100 more Leads and assign them to the sales manager of the opposite location. for (integer i=0; i<100; i++) { Lead l = new Lead(FirstName='LocationB', LastName='Lead' + i, Location__c = 'Location A', Company = 'NA', OwnerId = aId); leadList.add(l); } //close for-loop insert leadList; List <Lead> leads = [Select ID, FirstName from Lead Where FirstName like 'Location%' AND CreatedDate = TODAY limit 200]; // Create a Task for each Lead that was just inserted. Set the date of the task so that it will set the // Last Activity Date to a date older than your protection period. Task tsk = new Task(); tsk.WhoId = leads.get(i).Id; tsk.Status = 'Completed'; tsk.Subject = 'Test Subject'; tsk.Type = 'Call'; tasks.add(tsk); } // close for-loop try { insert tasks; } // Call the Batch Apex method. LeadReassignOnActivityHistory lr = new LeadReassignOnActivityHistory(); ID batchprocessid = Database.executeBatch(lr); Test.StopTest(); AsyncApexJob async = [Select Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems from AsyncApexJob where Id = :batchprocessid]; } //close testmethod } //close Class