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
Rahul H 4Rahul H 4 

Create Contact from Leads entity

Can you please help me to provide a trigger to Create Contact from Leads. Thanks 
Saransh BSaransh B
Contact will be created anyways once you "convert" Lead. Explian me more about your scenario.
Rahul H 4Rahul H 4
We have a business scenario wherein we create a new Lead, it should create a Contact. I am looking for an Apex trigger or process builder for this. Can you please help. 
Rahul H 4Rahul H 4
Sample code :

trigger LeadConvert on Lead (after update) 
{
Map<String, Lead> leadMap = new Map<String, Lead>();

        if(contEmailSet.size() > 0)
        {

            for(Lead leadObj: [Select Id, Name, Email, isConverted from Lead Where Email in: contEmailSet])
            {

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

                lc.setLeadId(leadObj.Id);
                lc.setAccountId(contMap.get(leadObj.Email).AccountId);
                lc.setContactId(contMap.get(leadObj.Email).Id);
                lc.setDoNotCreateOpportunity(true);

                LeadStatus convertStatus = [SELECT Id, MasterLabel, IsConverted FROM LeadStatus WHERE IsConverted=true limit 1];
                lc.setConvertedStatus(convertStatus.MasterLabel);

                try
                {
                    Database.LeadConvertResult lcResults = Database.convertLead(lc);
                }Catch(Exception exp)
                {
                    contMap.get(leadObj.Email).addError(exp.getMessage());
                }
            }
        }
    }