function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
anthonymossit1.3956973255286362E12anthonymossit1.3956973255286362E12 

Apex Test Class

I'm new to this and was hoping that someone could help me build an apex test class for the following trigger:

trigger ConvertLeadtrigger on Lead (after insert) {
//Bulkified
   Integer Count =0;
    Database.LeadConvert[] leadCollectionArray = new Database.LeadConvert[trigger.new.size()] ;
    for(Lead Lea : trigger.new){
        if(Lea.Convert__c == 'Trigger'){
          Database.LeadConvert convLead = new database.LeadConvert();
          convLead .setLeadId(Lea.Id);
          convLead.setConvertedStatus('Closed - Converted');
          convLead.setAccountID('001E000000M5uGr');
          convLead .setDoNotCreateOpportunity(true);
          leadCollectionArray[count] = convLead ;
          count++;
         }
    }
    Database.LeadConvertResult[] LeaConvResults = Database.convertLead(leadCollectionArray,false); 
}
Geetha28Geetha28
Try this,tested in mine,it covered the trigger 100%

@isTestPublic class TriggerTestClass{ 
      public static testMethod void TEST1(){ 

        //create new lead dont forget to include all required fields  
      Lead newlead= new Lead( LastName='test',Company='testcompany',Status='Open',Convert__c='Trigger'); 
       insert  newlead;     

    //check the value changed after trigger   

     system.assertequals('Closed - Converted',newlead.Status);
  }
}
anthonymossit1.3956973255286362E12anthonymossit1.3956973255286362E12
Seems to cover the code, but it's failing the test run - System.AssertException: Assertion Failed: Expected: Closed - Converted, Actual: Open.

This is working in my dev org. Any idea why it would be failing here? Thanks for your help!!
Geetha28Geetha28
You can debug it using system.debug(newlead.Status) before and after insert see the value changes are not . It should help you  to understand why its failing.