+ Start a Discussion

Weird Database.LeadConvert Issue

I'm trying to implement a custom Lead conversion operation using Apex. I had everything working fine until I added more than one possible "converted" Lead Status value. Initially, I had one "converted" Lead Status value ("Qualified"). When I execute the following code it converts fine:


Lead myLead = new Lead(FirstName='Test', LastName = 'Lead', Company='Test Company', Email='testlead@test.com');
myLead.RecordTypeId = [SELECT Id FROM RecordType WHERE DeveloperName='Client' AND SObjectType='Lead'].Id;
insert myLead;

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

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

Database.LeadConvertResult lcr = Database.convertLead(lc);


However, I've added a new "converted" Lead Status value called "Converted2" and added this to my Lead Process. When I execute the same code, only specifying the "Converted2" status as my converted status, I get the following error:


System.DmlException: ConvertLead failed. First exception on row 0; first error: INVALID_STATUS, invalid convertedStatus: Converted2: []


If I convert the Lead using the standard Lead conversion page, I am able to select "Converted2" as the converted status and the Lead converts successfully. Any ideas?


When you created the picklist value "Converted2", did you check the box to have it available during convert?  If not, that is probably the culprit.


Setup-->Customize-->leads-->fields-->status-->lead status picklist values


If you did check the box, please log a case as you should be able to select any lead status with the converted checkbox = true.



I did have the "Converted" checkbox checked on the "Converted2" status. I was actually able to select this status value as the converted status value if I converted the Lead via the standard Lead conversion page. It only seems to be problematic when I tried to set this as the converted status using the setConvertedStatus method on the Database.LeadConvert object.


I have opened a case with Salesforce on this.


Any luck from SF on this one? The same behavior just crept up in one of my sandboxes. Totally scratching my head on this one...


Hi Roarke - please log a case and we'll check it out.