+ Start a Discussion
RAMANJINEYULU GOGULARAMANJINEYULU GOGULA 

Unable map lead standard fields to opportunity custom fields

Initially I copied lead fields into lead custom fields after that I'm trying map Name and Email fields to Opportunity custom fields..

trigger mapping on Lead (after update) 
{
    Opportunity opp=new Opportunity();
    for(Lead ll:Trigger.New)
    {
        if(ll.isconverted==true)
        {
            opp.Client_Name__c=ll.Name;
            opp.Client_Email__c=ll.Email;
        }
        insert opp;
    }
}

This is working but opportunity fields not getting added. 
Best Answer chosen by RAMANJINEYULU GOGULA
Tim BarsottiTim Barsotti

Do you have "validation and triggers for lead convert" enabled for lead conversion? You will need this function enabled by SFDC for triggers to work on lead conversion. Once complete, the trigger should be like: 

trigger mapping on Lead (after update) {
    List<Opportunity> oppList = new List<Opportunity>();
    for(Lead ll:Trigger.New) {
        if(ll.isConverted==true && ll.ConvertedOpportunityId != null) {
            Opportunity opp = new Opportunity(Id = ll.ConvertedOpportunityId, Client_Name__c=ll.Name, Client_Email__c=ll.Email);
            oppList.add(opp);

        }
    }
    update oppList;
}

All Answers

Tim BarsottiTim Barsotti
Ramanjineyulu, you can map fields on the Lead Conversion without code. Navigate to Setup -> Lead -> Fields -> click button for "Map Lead Fields". Does this resolve your use case?
Tim BarsottiTim Barsotti

Do you have "validation and triggers for lead convert" enabled for lead conversion? You will need this function enabled by SFDC for triggers to work on lead conversion. Once complete, the trigger should be like: 

trigger mapping on Lead (after update) {
    List<Opportunity> oppList = new List<Opportunity>();
    for(Lead ll:Trigger.New) {
        if(ll.isConverted==true && ll.ConvertedOpportunityId != null) {
            Opportunity opp = new Opportunity(Id = ll.ConvertedOpportunityId, Client_Name__c=ll.Name, Client_Email__c=ll.Email);
            oppList.add(opp);

        }
    }
    update oppList;
}

This was selected as the best answer