I'm trying to use Database.LeadConvert to set Account fields based on a condition, as such:

 Database.LeadConvert lc= new Database.LeadConvert();
        lc.accountrecord.CustomField = 'Value';
        Database.leadConvertResult lcr = Database.convertLead(lc);

However I get a "Variable does not exist: CustomField" Error in the second to last line.

How would I go about achieving the task using Database.LeadConvert class?

Huge thanks in advance

1 Answer 1


If you look at the doc for LeadConvert class, you can see there is no property to allow specification of values on the converted-to Account, Contact, or Opportunity records.

At best you have setAccountId(id) which mimics the UX where the user can choose to use an existing accountId

The pattern you want to use are the Lead Mapping rules (Setup | Object Manager | Lead | Fields) that allow you to map fields on the Lead object to custom fields on the Account, Contact, and Opportunity objects

These Lead fields can be formulas or hidden-from-page layout.

In your example, you might have a formula field on Lead called Account_Custom_Field_X__c which has the desired value and you use the Lead Mapping rules to:

Lead                              Account
Account_Custom_Field_X__c   =>    Custom_Field_X__c

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .