+ Start a Discussion

Populating fields automatically during lead conversion



I want to autopopulate custom field values while converting lead to account, contact and opportunity.

I tried to map the lead fields, but is is getting mapped for only single object account or contact or opportunity.


Please let me know how i can populate the field values for all the three.



Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 

trigger LeadConvert on Lead (after update) {

  // no bulk processing; will only run from the UI
  if (Trigger.new.size() == 1) {

    if (Trigger.old[0].isConverted == false && Trigger.new[0].isConverted == true) {

      // if a new account was created
      if (Trigger.new[0].ConvertedAccountId != null) {

        // update the converted account with some text from the lead
        Account a = [Select a.Id, a.Type_of_Contact__c, a.Region__c,a.Country__c From Account a Where a.Id = :Trigger.new[0].ConvertedAccountId];
        a.Type_of_Contact__c = Trigger.new[0].Type_of_Contact__c;
        a.Please_specify_if_other__c = Trigger.new[0].Other__c;
        a.Region__c = Trigger.new[0].Region__c;
        a.Country__c = Trigger.new[0].Country__c;
        update a;


      // if a new contact was created
      if (Trigger.new[0].ConvertedContactId != null) {

        // update the converted contact with some text from the lead
        Contact c = [Select c.Id, c.Type_of_Contact__c, c.Region__c,c.Country__c From Contact c Where c.Id = :Trigger.new[0].ConvertedContactId];
        c.Type_of_Contact__c = Trigger.new[0].Type_of_Contact__c;
        c.Please_specify_if_other__c = Trigger.new[0].Other__c;       
        c.Region__c = Trigger.new[0].Region__c;
        c.Country__c = Trigger.new[0].Country__c;       
        update c;

      // if a new opportunity was created
      if (Trigger.new[0].ConvertedOpportunityId != null) {

        // update the converted opportunity with some text from the lead
        Opportunity o = [Select o.Id, o.Opportunity__c,o.Region__c,o.Country__c from Opportunity o Where o.Id = :Trigger.new[0].ConvertedOpportunityId];
        o.Opportunity__c = Trigger.new[0].Type_of_Contact__c;
        o.Please_Speci_if_other__c = Trigger.new[0].Other__c;       
        o.Region__c = Trigger.new[0].Region__c;
        o.Country__c = Trigger.new[0].Country__c;       
        update o;