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
pcroadkillpcroadkill 

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() {

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

//Invoke
test.startTest();
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());
test.stopTest();

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

}
}

SFAdmin5SFAdmin5

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

pcroadkillpcroadkill

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 : trigger.new){
if (l.ConvertedDate != null && l.ConvertedOpportunityId != null && trigger.oldMap.get(l.Id).isConverted == false){
oppDateMap.put(l.ConvertedOpportunityId, l.ConvertedDate);
}
}

if (!oppDateMap.isEmpty()){
HlprOpportunityFunctions.updateCloseDateOnConvertedOpp(oppDateMap);
}
}

 

 

public with sharing class HlprOpportunityFunctions {

@future
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);
oppList.add(o);
}

if (!oppList.isEmpty()){
try{
update oppList;
}catch (system.dmlException e){
system.debug(e.getDmlMessage(0));
}
}
}
}

SFAdmin5SFAdmin5

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

pcroadkillpcroadkill

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?