LeadConvert Class

Contains information used for lead conversion.

Namespace

Database

Usage

The convertLead Database method converts a lead into an account and contact, 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.

Note

Note

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

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, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
lc.setConvertedStatus(convertStatus.MasterLabel);

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.

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.
  • getContactId()
    Gets the ID of the contact into which the lead will be merged.
  • getConvertedStatus()
    Gets the lead status value for a converted lead.
  • getLeadID()
    Gets the ID of the lead to convert.
  • getOpportunityName()
    Gets the name of the opportunity to create.
  • getOwnerID()
    Gets the ID of the person to own any newly created account, contact, and opportunity.
  • isDoNotCreateOpportunity()
    Indicates whether an Opportunity is created during lead conversion (false, the default) or not (true).
  • 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).
  • isSendNotificationEmail()
    Indicates whether a notification email is sent to the owner specified by setOwnerId (true) or not (false, the default).
  • 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.
  • 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.
  • setConvertedStatus(status)
    Sets the lead status value for a converted lead. This field is required.
  • 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.
  • setLeadId(leadId)
    Sets the ID of the lead to convert. This field is required.
  • setOpportunityId(opportunityId)
    Sets the ID of the opportunity into which the lead is merged. This value is required only when updating an existing opportunity.
  • 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.
  • 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.
  • 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.
  • 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.

getAccountId()

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

Signature

public ID getAccountId()

Return Value

Type: ID

getContactId()

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

Signature

public ID getContactId()

Return Value

Type: ID

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

getOpportunityName()

Gets the name of the opportunity to create.

Signature

public String getOpportunityName()

Return Value

Type: String

getOwnerID()

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

Signature

public ID getOwnerID()

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

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

Important

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.

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.

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.

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