Ticker

6/recent/ticker-posts

Auto Convert Marketing Qualified Leads Using Apex and automates with Process Builder.

 


Apex Method

Now, we have to understand a new Apex annotation i.e. @InvocableMethod. This annotation lets us use an Apex method as being something that can be a call from somewhere other than Apex. The AutoConvertLeads class contains a single method that is passing the ids of the Leads whose Rating changed to Hot. Create the following class in your organization.

Public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(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); //Remove this line if you want to create an opportunity from Lead Conversion 
                MassLeadconvert.add(Leadconvert);
        }
        
        if (!MassLeadconvert.isEmpty()) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        }
    }
}  


First, write apex code after this code automates with Process Builder.

Follow the below instructions to create a Process Builder.

  • From Setup, enter Builder in the Quick Find box, and select Process Builder.
  • Click New.
  • For Process Name, type Contact address change.
  • For The process starts when, select A record changes, and click Save.
  • Click + Leads.
  • Select Lead object and for the entry criteria, Select when a record is created or edited, as shown in the below screenshot, once you are done click on the Save button.


  •  The next task is to add Process Criteria, To do this click on Add Criteria, enter NameType of action, and set filter conditions (In this case set [Lead].Rating Equals Hot as shown in the following screenshot.


  • Under Apex Class section, It will list out all the classes that contain methods annotated with @InvocableMethod Annotation.

  • Once you are done, click on the Save button, it will redirect you to Process canvas. Finally, the Process will look like the following screenshot.



  • Finally, click on the Activate button.


Post a Comment

0 Comments