+ Start a Discussion
Danielle Pulley 10Danielle Pulley 10 

Lead Deployment error

I tried deploying my test coverage for autolead convertion. below is the error I am recieving. Is there something with my code? 


Error:
System.DmlException: ConvertLead failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, convertedStatus is required.: [Status] 
Stack Trace: Class.TEST_LeadConvert.myUnitTest: line 17, column 1



CODE:

@IsTest private class TEST_LeadConvert{


private static testMethod void myUnitTest() {

// create a Lead
Lead lead=new Lead(LastName='Doe',FirstName='John',Company='Test',Status='New', );

insert lead;                

Database.LeadConvert lc = new database.LeadConvert();

//////////////////////////////////////////
lc.setLeadId(lead.id); //etc
//////////////////////////////////////////

Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());
}}


Thank you in advanced!
Amit Chaudhary 8Amit Chaudhary 8
Please try to update code like below
@IsTest private class TEST_LeadConvert{
	private static testMethod void myUnitTest() {

		Lead lead=new Lead(LastName='Doe',FirstName='John',Company='Test',Status='New', );
		insert lead;                

        database.leadConvert lc = new database.leadConvert();
        lc.setLeadId(lead.id);
        leadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        lc.setConvertedStatus(convertStatus.MasterLabel);
        
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess());
	
	}
}

Let us know if this will help you