+ Start a Discussion
Vishnu7700Vishnu7700 

Help to write test calss for leadconvert trigger

Hi,

Can any one help me to get codecoverage for leadconvert trigger

trigger ConvertLead on Lead (after insert , after update) {
    Integer Count = 0;
     //Array that stores all leads to convert
     Database.LeadConvert[] leadConvertarray = new Database.LeadConvert[trigger.new.size()];
        for(lead lea : Trigger.new){
            if(lea.LeadSource == 'Other' && lea.rating == 'Hot'){
                //Create new instance for variable
                Database.LeadConvert convrLead = new Database.LeadConvert();
                convrLead.setLeadId(lea.id);
                convrLead.setConvertedStatus('Closed - Converted');
                convrLead.setDoNotCreateOpportunity(False);
                leadConvertarray[Count]=convrLead;
                Count++;
                //System.debug('@@@@@@@@@Count'+ Count);
            }
        }
        //Array store actual count of lead converstion
        Database.LeadConvertResult[] LeaConvResults = Database.convertLead(leadConvertarray,false);
        //System.debug('@@@@@@@@@LeaConvResults'+ LeaConvResults);
    }

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

Check this

http://boards.developerforce.com/t5/Apex-Code-Development/Test-Coverage-for-Lead-Convert-Database-LeadConvertResult-lcr/td-p/568843

 

 If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

All Answers

souvik9086souvik9086

Check this

http://boards.developerforce.com/t5/Apex-Code-Development/Test-Coverage-for-Lead-Convert-Database-LeadConvertResult-lcr/td-p/568843

 

 If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

This was selected as the best answer
Vishnu7700Vishnu7700
 

Hi,

for below test method i'm getting 0% coverage.Can any help me.

@isTest
    public class ConvertLeadTest{
        static testMethod void test(){
            lead l1 = new lead(lastname = 'sample',LeadSource = 'Other',rating = 'Hot',Status = 'Closed - Converted');
            insert l1;
            
             Database.LeadConvert lc = new Database.LeadConvert();
                 lc.setLeadId(l1.id);
                 lc.setDoNotCreateOpportunity(true);
                 lc.setOverwriteLeadSource(false);
                 lc.setSendNotificationEmail(false);
                 LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
                 lc.setConvertedStatus(convertStatus.MasterLabel);
                 Database.LeadConvertResult lcr = Database.convertLead(lc);
        
           Account accts = new Account(name = 'sampleaccount',Type = 'Other');
              insert accts;
        
           //insert a Contact
           Contact con = new Contact (AccountId = accts.Id,FirstName = 'Contact',LastName = 'One');
              insert con;
       }
   }