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
saracsarac 

Database.ConvertLead() not working

Hello,

I amhaving trouble with the lead conversion call. The call to Database.ConvertLead does not seem to be working. It claims that the LeadStatus is not correct - but if you look in the Lead Processes, this status is in fact the converted status for that record type. AND you can also query the LeadStatus table:
Select l.MasterLabel, l.IsConverted, l.Id From LeadStatus l and see that 'Accepted' is in there with isConverted = true. I even did a select on that value as the MasterLabel to make sure that thre wasn't some odd whitespace issue.

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

I have tried all 4 lead statuses which are conversion endpoints and none works.

Any ideas are much appreciated!
Thanks,
Sara


Message Edited by sarac on 12-01-2008 06:41 PM
Best Answer chosen by Admin (Salesforce Developers) 
saracsarac
Hello,

Well, we're not actually having the lead conversion create any objects - I am creating the Account and Contact (or finding exisitng records) and populating them prior to that call. Two other custom objects are created as well (no opportunities in one case, 3 in another). We are just calling convertLead to set the isConverted flag on the Lead since it is not accessible via the API. I would think the validation rule would fire and throw any errors on insert of the new objects prior to causing an issue in the convertLead call?

To answer your question: there are no validation rules on Account, it fails in the call when no opportunities are created, so I will assume any rules on that object are irrelevant, and there is one rule on the Contact - that email can't be null. At least in the unit tests, Email is not null.

Thanks,
Sara


All Answers

ShamSham
Do you have any validation rules attached to Account,Contact or Opportunity ?
saracsarac
Hello,

Well, we're not actually having the lead conversion create any objects - I am creating the Account and Contact (or finding exisitng records) and populating them prior to that call. Two other custom objects are created as well (no opportunities in one case, 3 in another). We are just calling convertLead to set the isConverted flag on the Lead since it is not accessible via the API. I would think the validation rule would fire and throw any errors on insert of the new objects prior to causing an issue in the convertLead call?

To answer your question: there are no validation rules on Account, it fails in the call when no opportunities are created, so I will assume any rules on that object are irrelevant, and there is one rule on the Contact - that email can't be null. At least in the unit tests, Email is not null.

Thanks,
Sara


This was selected as the best answer