Header Ads Widget

How to Convert Leads to a Person and Business Account at the Same Time | Spring 21 New Feature

 

If in your Salesforce Implementation, you are dealing with both individual and group accounts, then with the release of Spring 21, now you can link your converted leads into both individual and group accounts with the new LeadConvert Methods.

Note 

This feature is only available in Enterprise, Performance, and Unlimted Editions.

Video

If you prefer video, here is the youtube video 



Methods

The new LeadConvert methods will allow you to link converted leads into a business and person account instead of a contact. Below are the methods available -
  • getRelatedPersonAccountId() - Gets the Id of an existing person account to convert the lead into.
  • setRelatedPersonAccountId(String personAccountId) - Sets the Id of an existing person accoung to convert the lead into.
  • getRelatedPersonAccountRecord() - Gets the entity record of a new person account to convert the lead into.
  • setRelatedPersonAccountRecord(Entity relatedPersonAccountRecord) - Sets the entity record of a new person account to convert the lead into.
LeadConvertResult class holds the result of the lead conversion.

Example 1

The below example uses the existing personAccountId to convert the lead into. After the execution of this method, lead with id leadId will be converted into both business account with id businessAccountId and person account with id personAccountId.

public static void convertLeadWithExistingPersonAccount(String leadId,
    String businessAccountId, String personAccountId, String opportunityId) {
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(leadId);
lc.setAccountId(businessAccountId);

//New Method to use the existing person account id to convert the lead into.
lc.setRelatedPersonAccountId(personAccountId);
lc.setOpportunityId(opportunityId);
lc.setSendNotificationEmail(false);

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

Database.LeadConvertResult lcr = Database.convertLead(lc);
}


Example 2

The below example created a new person account to convert the lead into. After the execution of this method, lead with id leadId will be converted into both business account with id businessAccountId and a new person account will be created, which will then be used to convert the lead into.

public static void convertLeadWithNewPersonAccount(String leadId, String businessAccountId) {
Database.LeadConvert lc = new Database.LeadConvert();
lc.setLeadId(leadId);
lc.setAccountId(businessAccountId);

//New Method to create new person account and then use the id
        //to the convert the lead into.
Account pacc = [SELECT
                            Id,
                            lastname,
                            isPersonAccount
                        FROM Account
                        WHERE isPersonAccount=true
                        LIMIT 1];
pacc.lastname='PersonAccount Last Name';
pacc.Id = null;
lc.setRelatedPersonAccountRecord(pacc);
lc.setSendNotificationEmail(false);

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

Database.LeadConvertResult lcr = Database.convertLead(lc);
}


Please let me know your feedback. Thanks.

Post a Comment

0 Comments