Sharing is caring!
When the Salesforce Lead record is converted into Accounts, Contacts & Opportunities, it is called Lead conversion. When the Salesforce lead is identified as a qualified Salesforce prospect, Lead conversion occurs.
The lead conversion process is a manual process, and the lead is being converted under the following conditions:
- When the lead data is populated in the contact, account, and opportunity. (unless specified otherwise at the time of conversion).
- The lead status field is changed from false to true.
In this blog, we will talk about how to automate it using Apex code and Salesforce Lightning Flow.
Flow Chart To Convert the Lead
What Are The Two Steps To Convert Lead Using Flow?
There are two steps to convert lead using flow:
- Create an Apex class and test class
- Lightning Flow Steps are:
- Record triggered flow
- Adding an action to Call an Apex Class
2. Lightning Flow Steps: Take the following steps to create a flow and set conditions for record triggered flow type.
How To Create A Flow And Set Trigger Conditions?
- Click Setup.
- Search Flows in the Quick Find box.
- Select Flows, then click on the New Flow.
- Select the Record-Triggered Flow and then follow the below steps:
- Freeform
- A record is created or Updated
- After the record is saved
- Lead
- Select All Conditions Are Met (AND) as shown in the below diagram.
- Set Conditions (as shown in the below diagram) as:
- Field: Lead | Rating
- Operator: Equals
- Value: Hot
- Choose the Option to Only when a record is updated to meet the condition requirements.
- Click Done.
Moving forward, we will show you how to create an Apex class and a Test class.
- How to Create an Apex class and Test class?
- Click Setup.
- Type Apex Classes in the Quick Find box.
- Clicks on the New button.
- Copy code from the below and paste it into your Apex Class.
- Click Save.
public class AutoConvertLeads {
@InvocableMethod
public static void assignLeads(List<Id> LeadIds){
LeadStatus cLeadStatus=[Select Id,MasterLabel from LeadStatus where isConverted=true limit 1];
List<Database.LeadConvert> massLeadConvert=new List<Database.LeadConvert>();
for(Id currentLead:LeadIds){
Database.LeadConvert LeadConvert=new Database.LeadConvert();
LeadConvert.setLeadId(currentLead);
LeadConvert.setConvertedStatus(cLeadStatus.MasterLabel);
LeadConvert.setDoNotCreateOpportunity(true);
massLeadConvert.add(LeadConvert);
}
if(!massLeadConvert.isEmpty()){
List<Database.LeadConvertResult> lcr=Database.convertLead(massLeadConvert);
system.debug(‘lcr:: ‘+lcr);
}
}
}
- Lightning Flow – Call an Apex Class
- Under Toolbox, select Element.
- Drag-and-drop Action element onto the Flow designer.
- In the Action box, type AutoConvertLeads.
- Click on the AutoConvertLeads apex class as shown in the below diagram:
- Enter a name in the Label field; the API Name will auto-populate.
- Set Input Values:
Row 1:
LeadIs: {!$Record.Id}
- Click Done.
Finally, we have to run the record-triggered flow after saving the record to take the action of the auto conversion of leads.
How to Add an Action?
- Click Save.
- Enter Flow Label and the API Name will LeadConversion
- Click Show Advanced.
- Type: Record-Triggered Flow
- Interview Label: Auto Convert Leads {!$Flow.CurrentDateTime}
- Click Save.
If a user updates the Lead Rating to Hot, Lightning Flow will automatically convert such leads and create an account and a contact.
Conclusion
Lead conversion in Salesforce is the process of converting Salesforce Lead records into Accounts, Contacts & Opportunities. It occurs when the Salesforce lead gets identified as a qualified Salesforce prospect. A lead is the default object in Salesforce created after receiving new contact information in your database. Leads can be imported or created automatically through an external marketing automation platform and form submissions. Lead conversion in Salesforce can be done using Apex Code and Lightning Flow that help businesses get a return on their investment.
Nitish Bhardwaj
Salesforce Principal Consultant | Chief Information Officer
An experienced Salesforce.com professional with 5+ years of experience in consulting on and delivering Salesforce projects for mid size, large and very large customers.Hire the best Salesforce Implementation Partner. Choose certified Salesforce Implementation Experts from Cloud Analogy now.