How to call invocable method (@InvocableMethod) from APEX Controller to convert automatic lead to Account, Contact and Opportunity Uses of Flow Builder/Flow Action in Salesforce | convert automatic lead to Account, Contact and Opportunity through apex class and flow action in Salesforce

2,595 views


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.

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
   

Live Demo

auto convert lead apex, automatically convert lead to account -- w3web.net

 

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

Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
   

leadConvertAutoCtrl.apxc [Apex Class Controller]

  1.    public class leadConvertAutoCtrl {
  2.    @InvocableMethod   
  3.     public static void LeadAssign(List<Id> LeadIds)  
  4.     {
  5.         List<String> conStr = NEW List<String>();
  6.         List<Contact> conList = [SELECT Id, FirstName, LastName, Email, Phone FROM Contact WHERE Phone !=NULL];
  7.         FOR(Contact con:conList){
  8.             conStr.add(con.Phone);
  9.         }
  10.         system.debug('conStr#__11 ' + conStr);
  11.  
  12.        Set<String> phStr = NEW Set<String>(); 
  13.         List<Lead> leadObjList = [SELECT Id, FirstName, LastName, Phone FROM Lead WHERE Id=:LeadIds];
  14.         FOR(Lead d1:leadObjList){
  15.             phStr.add(d1.Phone);
  16.             IF(conStr.contains(d1.Phone)){
  17.                 system.debug('do not allow duplicate phone');
  18.                 //d1.addError('do not allow duplicate phone');
  19.             }ELSE{
  20.                 /*Start lead convert*/ 
  21.         LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=TRUE LIMIT 1];    
  22.         List<DATABASE.LeadConvert> MassLeadconvert = NEW List<DATABASE.LeadConvert>();    
  23.         FOR(id currentlead: LeadIds){                    
  24.             DATABASE.LeadConvert Leadconvert = NEW DATABASE.LeadConvert();    
  25.             Leadconvert.setLeadId(currentlead);                               
  26.             Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);             
  27.             Leadconvert.setDoNotCreateOpportunity(FALSE); 
  28.             MassLeadconvert.add(Leadconvert); 
  29.  
  30.         }        
  31.  
  32.         IF (!MassLeadconvert.isEmpty())
  33.         {            
  34.             List<DATABASE.LeadConvertResult> lcr = DATABASE.convertLead(MassLeadconvert);       
  35.         }    
  36.       /*End lead convert*/
  37.             }
  38.         }
  39.         system.debug('phStr ' + phStr);
  40.  
  41.     } 
  42. }

Create Flow Builder/Flow Action in Salesforce

Step 2:- Create Flow Builder ➑ Flow Action ➑ flowLeadConvertAuto

Workflow & Approvals ➑ Flows ➑ New ➑ flowLeadConvertAuto

call invocable method from apex to create automatic lead -- w3web.net

Further post that would you like to learn in Salesforce

 

 

 

FAQ (Frequently Asked Questions)

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

 
Note:: – You will get an email, so put correct email and mobile number and BEGIN YOUR JOURNEY from Today!
 
 
  

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



Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment