+ Start a Discussion
mehelliemehellie 

Why is this test class not working?

@isTest
public class testContactServices{
    
    static testMethod void testTaskOnInsertHandler()
    {
        //Test.StartTest();
        // test Lead
        
       // Lead l = new Lead();
        
        
       // insert l;
        
        
        
        //Contact nc = new Contact();
        
    //insert nc;

        // test contact
          Task test = new Task();
    
          test.Type = 'Unqualified';
          test.Status = 'Completed';              
          test.WhoId = [select Id from Contact limit 1].Id; // to get an existing one.
          insert test;
            Map<ID,Task> contactmap = new Map<ID,Task>();
          contactmap.put(test.Id,test);
          
          ContactServices.taskOnInsertHandler(contactmap);
      
            // test lead
             Task test2 = new Task();

          test2.Type = 'Unqualified';
          test2.Status = 'Completed';              
          test2.WhoId = [select Id from Lead limit 1].Id; // to get an existing one.
          insert test2;
            Map<ID,Task> leadmap = new Map<ID,Task>();
          leadmap.put(test2.Id,test2);
      LeadServices.taskOnInsertHandler(leadmap);
     
        //Test.StopTest();
    }

}

 I'm probably missing something obvious, sorry. The referenced classes just push the "Type" field from a Task onto a "Task Type" field on the contact/lead. 

Best Answer chosen by Admin (Salesforce Developers) 
testrest97testrest97
@isTest(SeeAllData=true)

All Answers

testrest97testrest97
@isTest(SeeAllData=true)
This was selected as the best answer
mehelliemehellie
Yep, thanks!