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
NavneethNavneeth 

Lead Conversion trigger code

Hi i need a Lead conversion trigger code to convert lead to account/contact. The trigger should use standard database.leadconvert() method. The following is the skeleton of how the trigger should work. Please give me the code asap as it is urgent Please find the details of lead conversion Trigger on Lead Trigger on lead( after insert) { Get the trigger size (Integer)- takelist of type ---this list is used to hold the leads that needs to be converted Query the lead Status Isconverted=true(where condition)[ id,Masterlable, should be fetched] iterate For( i=0;-declared at the top } //create Database.LeadConvertResult[] array—Shown below [you can use exact line shown below] Database.LeadConvertResult[] leadResult= Database.convertLead(pass the listOfleads that needs to be converted,false); //itereate the leadResult and check the system.debug to know the success or failure
Peter_sfdcPeter_sfdc

What behavior are you after in the lead conversion process that isn't already done by the convert lead feature in the UI? Is it that you want certain leads to be auto converted upon creation? 

 

Also, could you please format your code? It is very difficult to read! Use the "Insert Code" button on the editor. Thanks!

NavneethNavneeth
Please find the exact details/skeleton of lead conversion 

Trigger on Lead
Trigger on lead( after insert)
{
Get the trigger size (Integer)-

take list of type <database.leadStatus>---this list is used to hold the leads that needs to be converted

Query the lead Status  Isconverted=true(where condition)[ id,Masterlable, should be fetched]

iterate For( i=0;<triggerSize;i++)

{
Create new instance of database.leadconvert
 
set the following values to instance 

set the leadID("id from trigger"),
notCreateOpportunity to(" true")
set convertedstatus(this value from the leadStatus Query)

after setting the values to instance add it to the list of type<database.leadStatus>-declared at the top
}


//create Database.LeadConvertResult[] array — Shown below [you can use exact line shown below]

Database.LeadConvertResult[] leadResult= Database.convertLead(pass the listOfleads that needs to be converted,false);


//itereate the leadResult and check the system.debug to know the success or failure