LeadConvert Class

Contains information used for lead conversion.

Database

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.

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.

The following are constructors for LeadConvert.

  • LeadConvert()

    Creates a new instance of the Database.LeadConvert class.

Creates a new instance of the Database.LeadConvert class.

public LeadConvert()

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

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

public ID getAccountId()

Type: ID

This method is for internal use only.

This method is for internal use only.

This method is for internal use only.

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

public ID getContactId()

Type: ID

This method is for internal use only.

Gets the lead status value for a converted lead.

public String getConvertedStatus()

Type: String

Gets the ID of the lead to convert.

public ID getLeadID()

Type: ID

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

public ID getOpportunityId()

Type: ID

Gets the name of the opportunity to create.

public String getOpportunityName()

Type: String

This method is for internal use only.

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

public ID getOwnerID()

Type: ID

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

public ID getRelatedPersonAccountId()

Type: ID

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

public ID getRelatedPersonAccountRecord()

Type: ID

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

public Boolean isDoNotCreateOpportunity()

Type: Boolean

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).

public Boolean isOverWriteLeadSource()

Type: Boolean

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

public Boolean isSendNotificationEmail()

Type: Boolean

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.

public Void setAccountId(ID accountId)

  • accountId: Type: ID

Type: Void

This method is for internal use only.

This method is for internal use only.

This method is for internal use only.

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.

public Void setContactId(ID contactId)

  • contactId: Type: ID

Type: Void

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.

This method is for internal use only.

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

public Void setConvertedStatus(String status)

Type: Void

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.

public Void setDoNotCreateOpportunity(Boolean createOpportunity)

Type: Void

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

public Void setLeadId(ID leadId)

  • leadId: Type: ID

Type: Void

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

public Void setOpportunityId(ID opportunityId)

  • opportunityId: Type: ID

Type: Void

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

public Void setOpportunityName(String opportunityName)

  • opportunityName: Type: String

Type: Void

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.

This method is for internal use only.

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.

public Void setOverwriteLeadSource(Boolean overwriteLeadSource)

  • overwriteLeadSource: Type: Boolean

Type: Void

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.

public Void setOwnerId(ID ownerId)

  • ownerId: Type: ID

Type: Void

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.

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.

public Void setRelatedPersonAccountId(ID relatedPersonAccountId)

  • relatedPersonAccountId: Type: ID

Type: Void

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

public Void setSendNotificationEmail(Boolean sendEmail)

Type: Void