LeadConvert Class

Contains information used for lead conversion.

Namespace

Database

Usage

The convertLead Database method converts a lead into an account and contact or an account and person account, as well as (optionally) an opportunity. The convertLead takes an instance of the Database.LeadConvert class as a parameter. Create an instance of this class and set the information required for conversion, such as setting the lead, and destination account and contact.

The Database.convertLead() method can take one LeadConvert object or a list of LeadConvert objects.

Note

Example

This example shows how to use the Database.convertLead method to convert a lead. It inserts a new lead, creates a LeadConvert object, sets its status to converted, then passes it to the Database.convertLead method. Finally, it verifies that the conversion was successful.

Lead myLead = new Lead(LastName = 'Fry', Company='Fry And Sons');
insert myLead;

Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(myLead.id);

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

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

LeadConvert Constructors

The following are constructors for LeadConvert.

LeadConvert()

Creates a new instance of the Database.LeadConvert class.

Signature

public LeadConvert()

LeadConvert Methods

The following are methods for LeadConvert. All are instance methods.

getAccountId()

Gets the ID of the account into which the lead will be merged.

Signature

public ID getAccountId()

Return Value

Type: ID

getAccountRecord()

This method is for internal use only.

getBypassAccountDedupeCheck()

This method is for internal use only.

getBypassContactDedupeCheck()

This method is for internal use only.

getContactId()

Gets the ID of the contact into which the lead will be merged.

Signature

public ID getContactId()

Return Value

Type: ID

getContactRecord()

This method is for internal use only.

getConvertedStatus()

Gets the lead status value for a converted lead.

Signature

public String getConvertedStatus()

Return Value

Type: String

getLeadID()

Gets the ID of the lead to convert.

Signature

public ID getLeadID()

Return Value

Type: ID

getOpportunityId()

Gets the ID of the existing opportunity that will be related to the resulting contact.

Signature

public ID getOpportunityId()

Return Value

Type: ID

getOpportunityName()

Gets the name of the opportunity to create.

Signature

public String getOpportunityName()

Return Value

Type: String

getOpportunityRecord()

This method is for internal use only.

getOwnerID()

Gets the ID of the person to own any newly created account, contact, and opportunity.

Signature

public ID getOwnerID()

Return Value

Type: ID

getRelatedPersonAccountId()

Gets the ID of the existing person account into which the lead will be converted.

Signature

public ID getRelatedPersonAccountId()

Return Value

Type: ID

getRelatedPersonAccountRecord()

Gets the entity record of the new person account into which the lead will be converted.

Signature

public ID getRelatedPersonAccountRecord()

Return Value

Type: ID

isDoNotCreateOpportunity()

Indicates whether an Opportunity is created during lead conversion (false, the default) or not (true).

Signature

public Boolean isDoNotCreateOpportunity()

Return Value

Type: Boolean

isOverWriteLeadSource()

Indicates whether the LeadSource field on the target Contact object is overwritten with the contents of the LeadSource field in the source Lead object (true), or not (false, the default).

Signature

public Boolean isOverWriteLeadSource()

Return Value

Type: Boolean

isSendNotificationEmail()

Indicates whether a notification email is sent to the owner specified by setOwnerId (true) or not (false, the default).

Signature

public Boolean isSendNotificationEmail()

Return Value

Type: Boolean

setAccountId(accountId)

Sets the ID of the account into which the lead is merged. This value is required only when updating an existing account, including person accounts.

Signature

public Void setAccountId(ID accountId)

Parameters

accountId
Type: ID

Return Value

Type: Void

setAccountRecord(accountRecord)

This method is for internal use only.

setBypassAccountDedupeCheck(bypassAccountDedupeCheck)

This method is for internal use only.

setBypassContactDedupeCheck(bypassContactDedupeCheck)

This method is for internal use only.

setContactId(contactId)

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.

Signature

public Void setContactId(ID contactId)

Parameters

contactId
Type: ID

Return Value

Type: Void

Usage

If setContactId is specified, then the application creates a new contact that is implicitly associated with the account. The contact name and other existing data are not overwritten (unless setOverwriteLeadSource is set to true, in which case only the LeadSource field is overwritten).

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.

Important

setContactRecord(contactRecord)

This method is for internal use only.

setConvertedStatus(status)

Sets the lead status value for a converted lead. This field is required.

Signature

public Void setConvertedStatus(String status)

Parameters

status
Type: String

Return Value

Type: Void

setDoNotCreateOpportunity(createOpportunity)

Specifies whether to create an opportunity during lead conversion. The default value is false: opportunities are created by default. Set this flag to true only if you do not want to create an opportunity from the lead.

Signature

public Void setDoNotCreateOpportunity(Boolean createOpportunity)

Parameters

createOpportunity
Type: Boolean

Return Value

Type: Void

setLeadId(leadId)

Sets the ID of the lead to convert. This field is required.

Signature

public Void setLeadId(ID leadId)

Parameters

leadId
Type: ID

Return Value

Type: Void

setOpportunityId(opportunityId)

Sets the ID of the opportunity into which the lead is merged. This value is required only when updating an existing opportunity.

Signature

public Void setOpportunityId(ID opportunityId)

Parameters

opportunityId
Type: ID

Return Value

Type: Void

setOpportunityName(opportunityName)

Sets the name of the opportunity to create. If no name is specified, this value defaults to the company name of the lead.

Signature

public Void setOpportunityName(String opportunityName)

Parameters

opportunityName
Type: String

Return Value

Type: Void

Usage

The maximum length of this field is 80 characters.

If setDoNotCreateOpportunity is true, no Opportunity is created and this field must be left blank; otherwise, an error is returned.

setOpportunityRecord(opportunityRecord)

This method is for internal use only.

setOverwriteLeadSource(overwriteLeadSource)

Specifies whether to overwrite the LeadSource field on the target contact object with the contents of the LeadSource field in the source lead object. The default value is false, to not overwrite the field. If you specify this as true, you must also specify setContactId for the target contact.

Signature

public Void setOverwriteLeadSource(Boolean overwriteLeadSource)

Parameters

overwriteLeadSource
Type: Boolean

Return Value

Type: Void

setOwnerId(ownerId)

Specifies the ID of the person to own any newly created account, contact, and opportunity. If the application does not specify this value, the owner of the new object will be the owner of the lead.

Signature

public Void setOwnerId(ID ownerId)

Parameters

ownerId
Type: ID

Return Value

Type: Void

Usage

This method is not applicable when merging with existing objects—if setOwnerId is specified, the ownerId field is not overwritten in an existing account or contact.

setRelatedPersonAccountId(relatedPersonAccountId)

Sets the ID of the existing person account into which to convert the lead. This value is required only when updating an existing person account.

Signature

public Void setRelatedPersonAccountId(ID relatedPersonAccountId)

Parameters

relatedPersonAccountId
Type: ID

Return Value

Type: Void

setSendNotificationEmail(sendEmail)

Specifies whether to send a notification email to the owner specified by setOwnerId. The default value is false, that is, to not send email.

Signature

public Void setSendNotificationEmail(Boolean sendEmail)

Parameters

sendEmail
Type: Boolean

Return Value

Type: Void