Return to Snippet

Revision: 33861
at October 14, 2010 10:39 by leeclint


Initial Code
@isTest
private class LeadReassignOnActivityHistoryTest {

    static testMethod void TestLeadReassign() {
        
        // User Id's for the two sales managers.
        String aId = '005A0000000i84o';
        String bId = '005A0000000i84z';
        
        List <Lead> leadList = new List <Lead>();
        List <Task> tasks = new List <Task>();
        
        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.
        for (Integer i=0; i<200; i++) {
            Task tsk = new Task();
            tsk.WhoId = leads.get(i).Id;
            tsk.ActivityDate = System.today() - 11;
            tsk.Status = 'Completed';
            tsk.Subject = 'Test Subject';
            tsk.Type = 'Call';
            
            tasks.add(tsk);
            
        } // close for-loop
        
        try {
            insert tasks;
        } catch (System.DMLexception e) {
            System.debug('Task List not inserted: ' + e);
        }
        
            
        // 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];
        System.debug('Final results are ' + async);
        
        System.AssertEquals(async.NumberOfErrors, 0);
        System.AssertEquals([Select count() from Lead Where OwnerId=:aId AND FirstName='LocationA'], 100);
        System.AssertEquals([Select count() from Lead Where OwnerId=:bId AND FirstName='LocationB'], 100);
        System.AssertEquals([Select count() from Task Where Subject = 'Test Subject'], 200);
        
            
        
    } //close testmethod
    
} //close Class

Initial URL


Initial Description
This is the test class for the LeadReassignment class.

Initial Title
Test Class for Lead Reassignment

Initial Tags
class

Initial Language
Java