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

Auto populate custom picklists



I need help creating an apex trigger for one custom picklist to auto populate another custom picklist.


For example I have:


Lead Source Detail API Name: Lead_Source_Detail_C




Lead Source Detail v2 API Name: Lead_Source_Detail_v2_C


Both have the same values. When Lead source detail is selected and saved, I want Lead Source Detail v2 to auto populate with the same value. V2 is hidden and will be mapped to opportunities, while the original lead source is mapped to contacts.


These are the values:

Mike Ferry
NAR 2011
TriplePlay 2011
KW Family Reunion 2012
RealTrends Top 500
Generation Blue 2012
Acro Energy
ERA 2012
San Diego Summit 2012
Territory Analysis E-mail Campaign
Top Brokerage List
WCR 2012
NAR Mid Year 2012
BHG 5/2012
Coldwell Banker Seattle 2012
Hear it Direct - Texas
Ferry's Eagles
HSC Solar
FAR 2012
Top CA Solar Installs
Mega Camp 2012
CAR 2012
Hear it Direct 2012 - Irvine
NAR 2012 - FL
Triple Play 2012
Weekly Product Webinar
High Tech Farming 2012
Webinar - Jan 2013
Mike Ferry Campaign
KW FR 2013
High-Tech Farming KW 3.6.13
Webinar 4.16.13
The One Thing Offer
KW Mastermind April 2013
Webinar 5.8.13
Craig Proctor 1/2 Day
NAR Mid-Year 2013
Webinar 6.5.13
First American Demo 6.14.13
CB Sales Rally 2013
Craig Proctor Super Conference 2013
First American Demo 7.25.13


Thank you so much for the help! I'm completely new to Apex Triggers...




Do you need a trigger for this? Can't you do it with a Workflow Field Update?

trigger LeadTrigger on Lead(before insert, before update){
for(Lead__c lead :{
lead.Lead_Source_Detail_v2_C = lead.Lead_Source_Detail_C;
} }


As both the fields are picklists, a workflow might not help here because you cannot update a picklist field based on the value of another picklist field. You can just  select either the previous or the next picklist value. But if the hidden field is a just a simple text field, you can use a workflow field update to populate the hidden field with the value of the picklist field.


Hope this helps.




Satish Kumar

Please mark my answer as a solution if it was helpful so it is available to others as a proper solution.
If you felt I went above and beyond, please give me Kudos by clicking on the star icon.