+ Start a Discussion

Automatically convert lead to contact with opportunity?


I am Very new to SF... I need to do automatically convert lead to contact with opportunity. If contact is not exist we need to create new contact, if contact is exist we need not create contact, and this lead move into opportunity.

Please give Trigger Code for this task.

Thanks in advance.
I guess you wont want to use a trigger, it will most likely be a button that will, through some means, run apex code. 

Have a look at the leadconvert class doc : 

You will need your apex code to figure out if you need to create an account or not.

I know you would rather had a complete code solution, but you'll learn much more if you figure it out using clues :)

Hi Elie,

Thanks for your replay, I have taken below this code form net.

trigger ConvertLead on Lead (after insert, after update) {

for (Lead lead : Trigger.new) {
if (lead.isConverted == false) //to prevent recursion


Database.LeadConvert lc = new Database.LeadConvert();

String oppName = lead.Name;

LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];

Database.LeadConvertResult lcr = Database.convertLead(lc);


this is converting lead to opportunity but not immediately. After adding lead this code executed and ” Converted Lead ” page showing with contact, account and Opportunity values. After clicking this value only this record move to opportunity.

Why we need to click, after that only record move to contact , account , opportunity. I need auto convert.

Please advise.