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
David WrightDavid Wright 

Problem using Database.convertLead()

I have a trigger that runs on updated (converted) leads, so I need to be able to emulate that process in my Apex test class in order to test correctly. I've followed the documentation as instructed Here, but I'm getting an error during test execution that I'm not sure how to fix.

/*
* Test class for the TransferIndustryContacts trigger 
*/
public with sharing class Test_TransferIndustryContacts {

	//Declare test method
	public static testmethod void doTest() {
		
		//Create a new lead that will be converted into a new account and contact
		Lead newLead = new Lead(lastname = 'Test1_Lname', company='Test1_Acct');
		insert newLead;
		
		//Create the LeadConvert object
		Database.LeadConvert lc = new database.LeadConvert();
		
		//Set the newly inserted lead as the target to this LeadConvert
		lc.setLeadId(newLead.id);
		
		//Set the required ConvertedStatus field
		LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted = true limit 1];
		lc.setConvertedStatus(convertStatus.MasterLabel);
		
		//execute lead conversion
		Database.LeadConvertResult lcr = Database.convertLead(lc);
		
		//Confirm that the new contact belongs to the correct account
		//as assigned by the trigger (Account ID = 00100000005Q96h)
		Contact newContact = [SELECT Id, AccountId FROM Contact WHERE Id = :lcr.getContactId()];
		System.assert(newContact.AccountId == '00100000005Q96h');
	}

}

 The error occurs on the line that performs the database.convertLead() method, but the error it throws is:

 

"INVALID_STATUS, invalid convertedStatus: Qualified --> Account: []"

 

I know "Qualified --> Account"  is what is getting returned by the query to LeadStatus, but the option is a valid for the converted status during the lead conversion in the UI. I also tried hard coding in another option from this list to no avail. Any suggestions?

 

 

kevinvw2000kevinvw2000

I am running in to the same issue.  Did you get this resolved?