Hey guys, today in this post we are going to learn about How to Auto convert Lead from APEX Controller method as ‘@InvocableMethod‘ flow Uses of Flow Builder/Flow Action in Salesforce.
Real time scenarios:- Create Flow to call @invocable apex for Convert Auto Lead and add filter do not allow duplicate contact if Contact Phone already exist.
Files we used in this post example
leadConvertAutoCtrl.apex | Apex Controller | Call invocable method to convert automatic account, contact and opportunity in Salesforce |
create Flow >> flowLeadConvertAuto | Builder/Flow Action | Create Flow to call invocable apex for Lead Auto Convert |
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. To know more for convert auto lead, click here.
Live Demo
You can download file directly from github by Click Here.
Other related post that would you like to learn in Salesforce
- Find the below steps
Create Apex Class Controller
Step 1:- Create Apex Class : leadConvertAutoCtrl.apxc
From Developer Console ➡ File ➡ New ➡ Apex Class
leadConvertAutoCtrl.apxc [Apex Class Controller]
public class leadConvertAutoCtrl {
@InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
List<String> conStr = NEW List<String>();
List<Contact> conList = [SELECT Id, FirstName, LastName, Email, Phone FROM Contact WHERE Phone !=NULL];
FOR(Contact con:conList){
conStr.add(con.Phone);
}
system.debug('conStr#__11 ' + conStr);
Set<String> phStr = NEW Set<String>();
List<Lead> leadObjList = [SELECT Id, FirstName, LastName, Phone FROM Lead WHERE Id=:LeadIds];
FOR(Lead d1:leadObjList){
phStr.add(d1.Phone);
IF(conStr.contains(d1.Phone)){
system.debug('do not allow duplicate phone');
//d1.addError('do not allow duplicate phone');
}ELSE{
/*Start lead convert*/
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(FALSE);
MassLeadconvert.add(Leadconvert);
}
IF (!MassLeadconvert.isEmpty())
{
List<DATABASE.LeadConvertResult> lcr = DATABASE.convertLead(MassLeadconvert);
}
/*End lead convert*/
}
}
system.debug('phStr ' + phStr);
}
}
Create Flow Builder/Flow Action in Salesforce
Step 2:- Create Flow Builder ➡ Flow Action ➡ flowLeadConvertAuto
Workflow & Approvals ➡ Flows ➡ New ➡ flowLeadConvertAuto
Further post that would you like to learn in Salesforce
What happens when lead is converted in Salesforce?
When you convert a lead, Salesforce creates an account, contact, and optionally an opportunity, using information from the lead you're converting.
What is the difference between leads and opportunities in Salesforce?
A lead refers to an unqualified contact. They're unqualified because they still have doubts or uncertainty about your business and aren't ready to buy. An opportunity refers to the high probability of generating sales revenue.
What is Apex lead convert?
The convertLead Database method converts a lead into an account and contact or an account and person account, as well as (optionally) an opportunity.
Related Topics | You May Also Like
Our Free Courses →
👉 Get Free Course →
![]() 📌 Salesforce Administrators 📌 Salesforce Lightning Flow Builder 📌 Salesforce Record Trigger Flow Builder |
👉 Get Free Course →
![]() 📌 Aura Lightning Framework 📌 Lightning Web Component (LWC) 📌 Rest APIs Integration |