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

Test failing on lead convert

I am trying to deploy a new trigger and can't because the test below is failing. It is failing with the following error:


16:04:51.566 (566509000)|EXCEPTION_THROWN|[37]|System.DmlException: ConvertLead failed. First exception on row 0; first error: INVALID_STATUS, invalid convertedStatus: Qualified: []


Yet when I run the query specified in teh following line:


LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted = true LIMIT 1];


The status returned is 'Qualified' which is a valid status. Could anyone shed light on what may be going on... Thank you in advance.


private class TestPopulateCloseDateOnOppOnLeadConvert {

static testMethod void PopulateCloseDateOnOppOnLeadConversion() {

Lead lead = new Lead(LastName='Test', Company='Test', Business_Unit__c='EPS', CurrencyISOCode='USD', Status='Unqualified');
insert lead;

Database.LeadConvert lc = new Database.LeadConvert();
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted = true LIMIT 1];
Database.LeadConvertResult lcr = Database.convertLead(lc);

id oppId = lcr.getOpportunityId();
Opportunity opp = [SELECT Id, CloseDate FROM Opportunity WHERE Id = :oppId];
system.assertEquals(, opp.CloseDate);



hi.  would you mind posting your trigger for us?  thanks a lot.


Here's the trigger and the helper class:


trigger PopulateCloseDateOnOppOnLeadConverion on Lead (after update) {

map<id, date> oppDateMap = new map<id, date>();

for (Lead l :{
if (l.ConvertedDate != null && l.ConvertedOpportunityId != null && trigger.oldMap.get(l.Id).isConverted == false){
oppDateMap.put(l.ConvertedOpportunityId, l.ConvertedDate);

if (!oppDateMap.isEmpty()){



public with sharing class HlprOpportunityFunctions {

public static void updateCloseDateOnConvertedOpp(map<id, date> oppDateMap){

list<Opportunity> oppList = new list<Opportunity>();

for (Opportunity o : [SELECT Id, CloseDate FROM Opportunity WHERE Id IN :oppDateMap.keySet()]){
o.CloseDate = oppDateMap.get(o.Id).addDays(3);

if (!oppList.isEmpty()){
update oppList;
}catch (system.dmlException e){


thanks.  I'm looking at your code now but it would help if you can provide, in words, what you want to accomplish here.  thanks a lot


When users convert a lead, the anticipated closed/won date for the new opportunity gets set to three days from the date the Lead was converted. So the trigger basically does that, it adds three days by getting the convert date from the lead.


Is this enough info or do you need more detail.

Ron ReedRon Reed

Is the Converted checkbox checked next to your "Qualified" picklist value?