• Roarke
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

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();
lc.setLeadId(myLead.id);

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true AND MasterLabel = 'Qualified' LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);

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

 

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?

  • October 25, 2011
  • Like
  • 0