LeadConvert Class
Namespace
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.
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 Methods
The following are methods for LeadConvert. All are instance methods.
getAccountId()
Signature
public ID getAccountId()
Return Value
Type: ID
getContactId()
Signature
public ID getContactId()
Return Value
Type: ID
getConvertedStatus()
Signature
public String getConvertedStatus()
Return Value
Type: String
getOpportunityId()
Signature
public ID getOpportunityId()
Return Value
Type: ID
getOpportunityName()
Signature
public String getOpportunityName()
Return Value
Type: String
getOwnerID()
Signature
public ID getOwnerID()
Return Value
Type: ID
getRelatedPersonAccountId()
Signature
public ID getRelatedPersonAccountId()
Return Value
Type: ID
getRelatedPersonAccountRecord()
Signature
public ID getRelatedPersonAccountRecord()
Return Value
Type: ID
isDoNotCreateOpportunity()
Signature
public Boolean isDoNotCreateOpportunity()
Return Value
Type: Boolean
isOverWriteLeadSource()
Signature
public Boolean isOverWriteLeadSource()
Return Value
Type: Boolean
isSendNotificationEmail()
Signature
public Boolean isSendNotificationEmail()
Return Value
Type: Boolean
setAccountId(accountId)
Signature
public Void setAccountId(ID accountId)
Parameters
- accountId
- Type: ID
Return Value
Type: Void
setContactId(contactId)
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).
setConvertedStatus(status)
Signature
public Void setConvertedStatus(String status)
Parameters
- status
- Type: String
Return Value
Type: Void
setDoNotCreateOpportunity(createOpportunity)
Signature
public Void setDoNotCreateOpportunity(Boolean createOpportunity)
Parameters
- createOpportunity
- Type: Boolean
Return Value
Type: Void
setLeadId(leadId)
Signature
public Void setLeadId(ID leadId)
Parameters
- leadId
- Type: ID
Return Value
Type: Void
setOpportunityId(opportunityId)
Signature
public Void setOpportunityId(ID opportunityId)
Parameters
- opportunityId
- Type: ID
Return Value
Type: Void
setOpportunityName(opportunityName)
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)
Signature
public Void setOverwriteLeadSource(Boolean overwriteLeadSource)
Parameters
- overwriteLeadSource
- Type: Boolean
Return Value
Type: Void
setOwnerId(ownerId)
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)
Signature
public Void setRelatedPersonAccountId(ID relatedPersonAccountId)
Parameters
- relatedPersonAccountId
- Type: ID
Return Value
Type: Void
setSendNotificationEmail(sendEmail)
Signature
public Void setSendNotificationEmail(Boolean sendEmail)
Parameters
- sendEmail
- Type: Boolean
Return Value
Type: Void