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
JaredPHJaredPH 

Help? Simple trigger to map lead type to standard opportunity type?

Hi everyone,

I'm terrible at coding, but was hoping someone would be feeling kind enough to help me with a simple trigger that maps the value of a custom lead field to the standard opportunity "type" field on conversion. The name of the field is lead_type__c

Any help that anyone could give would really be appreciated. Thanks so much!


vmanumachu1.393650924860069E12vmanumachu1.393650924860069E12
Here you go:

trigger trgUpdateType on Lead (before update) {
List<Lead> leads = Trigger.new;
Map<Id,string> oppids = new Map<Id,string>();
List<string> stropps = new List<string>();
for(Lead ld : leads)
{
  if(ld.IsConverted)
  {  
   oppids.put(ld.ConvertedOpportunityId,ld.Type__c);
   stropps.add(ld.ConvertedOpportunityId);
  }
}
List<Opportunity> opps = [select Type from Opportunity where Id IN: stropps];
for(Opportunity opp : opps)
{
  opp.Type = oppids.get(opp.Id);
}
update opps;
}