[SalesForce] Lead Conversion to Opportunity

I need to convert Leads into just an Opportunity because for various reasons the Account and Contacts for the Lead record will have been created separately. From the convertLead() docs is seems that if you use this method then you have to create an Account and Contact record on conversion.

Use convertLead() to convert a Lead into an Account and Contact, as well as (optionally) an Opportunity.

Is this correct?

If so, then I would have to create the Opportunity separately which is fine except that I still need to mark the Lead as converted, but I see that the isConverted field is non-writable.

Would really like to find out about methods to convert a Lead into just an Opportunity and whether I can explicitly set a Lead to isConverted by code.

Best Answer

Take a look at the documentation:

There you have the ability to provide an existing AccountId and ContactId with the methods setAccountId() and setContactId(), respectively.

You just have to make sure that your contact is associated with the account you provide in AccountId, and if you use PersonAccounts, don't provide the ContactId

setAccountId Sets the ID of the account into which the lead will be merged. This value is required only when updating an existing account, including person accounts. Otherwise, if setAccountID is specified, a new account is created.

setContactId Sets the ID of the contact into which the lead will be merged (this contact must be associated with the account specified with setAccountId, and setAccountId must be specified). This value is required only when updating an existing contact.Important If you are converting a lead into a person account, do not specify setContactId or an error will result. Specify only setAccountId of the person account. If setContactID is specified, then the application creates a new contact that is implicitly associated with the account.

Related Topic