0

I have created custom name, email, phone fields on lead apart from standard name email and phone fields. I want, when lead qualified and converted so it should be created as new contact under the same company name. How can I achieve this?

Please find below trigger:

trigger LeadConvert on Lead (after update) {

map<Id, Lead> mapNewLead = trigger.newMap;
List<Contact> lstContact = new List<Contact>();
for(Lead objLead: mapNewLead.values())
{
   if (objLead.isConverted == true) 
   {
     lstContact.add(new contact(LastName = objLead.First_Other_Contact_Name__c));
     lstContact.add(new contact(Phone = objLead.First_Other_Contact_Phone__c));
     lstContact.add(new contact(Email = objLead.First_Other_Contact_Email__c));
   }
}
insert lstContact;
}

enter image description here

0

1 Answer 1

1

When sales reps convert qualified leads, the information from the standard lead fields appears in standard fields for contact, account, and opportunity records. If you set up custom lead fields, you specify how that custom information converts to custom fields in accounts, contacts, and opportunities.

  1. From the object management settings for leads, go to the fields section, then click Map Lead Fields.
  2. For each custom lead field, choose a custom account, contact, or opportunity field into which you want the information inserted when you convert a lead.
  3. Save your work.

Updates

trigger LeadConvert on Lead (after update) { 

    map<Id, Lead> mapNewLead = trigger.newMap; 
    List<Contact> lstContact = new List<Contact>(); 
    for(Lead objLead: mapNewLead.values()) 
    { 
        if (objLead.isConverted == true && objLead.ConvertedAccountId != null) 
        { 
            lstContact.add(new contact(LastName = objLead.First_Other_Contact_Name__c,
                                        Phone = objLead.First_Other_Contact_Phone__c,
                                        Email = objLead.First_Other_Contact_Email__c, 
                                        AccountId = objLead.convertedAccountId));
        } 
    } 
    insert lstContact; 
}
9
  • Hi Ratan, Good to see you again. My issue is different. I have created 3 text fields as alternative contacts. So I want when we convert lead all name text field convert as a new contacts. @ratan Feb 14, 2016 at 11:25
  • Any approach. should I write trigger on contact object or lead object. Feb 14, 2016 at 11:54
  • I have seen but this trigger just overriding the standard process. I don't want to override standard process. I just want apart from main contact name, If any other name details I fill into lead so during the conversion process all other name should be create as a new contacts in same account. @Ratan Feb 14, 2016 at 12:33
  • Can I create 4 contacts through 1 lead conversion because I have created 3 Names, Email and Phone fields. @Ratan Feb 14, 2016 at 12:43
  • Hi @Ratan I am getting below error "Error: LeadConvert: execution of AfterUpdate caused by: System.DmlException: Insert failed. First exception on row 1; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Last Name]: [Last Name] ()" but u have entered last name. Feb 15, 2016 at 5:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .