function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chirstinachirstina 

Help Regarding Lead Conversion

Hi

 

I want to convert a lead to account and contact immediately when the lead status is changed to closed... is it possible to convert it through workflow rule or i have to go with trigger .....

 

 

Regards

Christina

Best Answer chosen by Admin (Salesforce Developers) 
hitesh90hitesh90

Hi,

 

Below is the sample Example as per your requirement. you have to create one class also

to handle recursive call trigger because it is on after update.

 

Apex Class:

public class clsHandlerecursive{
      public static boolean isLeadUpdate = true;
}

 

Apex Trigger:

trigger ConvLeadtrigger on Lead (after insert, after update) {
    if(clsHandlerecursive.isLeadUpdate == true){
        Database.LeadConvert[] leadCollectionArray = new Database.LeadConvert[]{};
        for(Lead mylead : trigger.new){
            if((myLead.status == 'Closed - Converted')){
                Database.LeadConvert lc = new database.LeadConvert();
                lc.setLeadId(mylead.Id);
                lc.setConvertedStatus('Closed - Converted');
                lc.setDoNotCreateOpportunity(true);
                leadCollectionArray.add(lc);
            }
        }
        system.debug('######'+leadCollectionArray);
        clsHandlerecursive.isLeadUpdate = false;
        Database.LeadConvertResult[] lcr = Database.convertLead(leadCollectionArray);
    }
}

 

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

 

All Answers

hitesh90hitesh90

Hi Chirstina,

 

You must have to use Apex Trigger to fulfill your requirement.
here is sample trigger example for conver Lead through trigger.

Lead Conversion Trigger Exampler

 

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

chirstinachirstina

I am not able to get the solution you gave... actually i m not that much sufficient to write triggers ...

 

Regards

Christina

hitesh90hitesh90

Hi,

 

Below is the sample Example as per your requirement. you have to create one class also

to handle recursive call trigger because it is on after update.

 

Apex Class:

public class clsHandlerecursive{
      public static boolean isLeadUpdate = true;
}

 

Apex Trigger:

trigger ConvLeadtrigger on Lead (after insert, after update) {
    if(clsHandlerecursive.isLeadUpdate == true){
        Database.LeadConvert[] leadCollectionArray = new Database.LeadConvert[]{};
        for(Lead mylead : trigger.new){
            if((myLead.status == 'Closed - Converted')){
                Database.LeadConvert lc = new database.LeadConvert();
                lc.setLeadId(mylead.Id);
                lc.setConvertedStatus('Closed - Converted');
                lc.setDoNotCreateOpportunity(true);
                leadCollectionArray.add(lc);
            }
        }
        system.debug('######'+leadCollectionArray);
        clsHandlerecursive.isLeadUpdate = false;
        Database.LeadConvertResult[] lcr = Database.convertLead(leadCollectionArray);
    }
}

 

Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator
My Blog:- http://mrjavascript.blogspot.in/

 

This was selected as the best answer
chirstinachirstina

Hey 

Thnx a lot for the solution.

 

 

Regards

Christina