+ Start a Discussion
Sunil Kumar 545Sunil Kumar 545 

hi ,lead conversion uisng apex class

check whether email is there or not in lead object ...if lead exist means convert to contact and account 
if it does not exist means it sholud be contact using apex class ...send code in only apex class..
Prema -Prema -
Hello Sunil, Do you mean to say that if an email exists on Lead record then you want to convert the lead to Contact and Account?
Sunil Kumar 545Sunil Kumar 545
yes tht thing only ..
Sunil Kumar 545Sunil Kumar 545
if we create new record in lead object email it should convert to account and contact .does not create means it should create new contact in apex class
Akshay_DhimanAkshay_Dhiman
Hi Sunil Kumar 545,

It helps you:
 
trigger ToCreateContactWhenLead on Lead (before insert) 
{
    List<Lead> leadList = new List<Lead>();
    List<Account> acctList = new List<Account>();
    List<Contact> conList = new List<Contact>();
    for(Lead leadObj : trigger.new)
    {    
        if(leadObj.Email !=  null)
        {
            Account acctObj = new Account();
            acctObj.Name = leadObj.LastName;
            Contact conObj = new Contact();
            conObj.LastName = leadObj.Name;
            conObj.Email = leadObj.Email;
            acctList.add(acctObj);
            conList.add(conObj);
            
        }
          
        leadList.add(leadObj);
    }
        if(acctList.size()>0 || conList.size()>0)
        {
            insert acctList;
            insert conList;
        }
}

If you found this answer helpful then please mark it as best answer so it can help others.   
  
  Thanks 
  Akshay​