+ Start a Discussion
Michael BobeeMichael Bobee 

Transfer a custom picklist value from a product to an Opportunity product

When a new Opportunity Product record is added to an Opportunity, I would like to take the value from a custom picklist on the selected/associated product and transfer that value to a custom picklist on the Opportunity Product. This would preserve the ability to edit the value if the default picklist value needs to be edited. I explored several workflow/field update options, but because it's a picklist,- it creates some unique challenges. Maybe a trigger?
Hi Michael,

Yes, you should go for a trigger. Here is a sample:

trigger updatePick on OpportunityLineItem (after insert) {
    set<Id> Ids = new set<Id>();
    list<opportunitylineitem> updateolelist = new list<opportunitylineitem>();
    for(opportunitylineitem ol:trigger.new){
    map<Id,product2> pmap = new map<Id,product2>([select Id,pickprod__c from product2 where Id IN :Ids]);
    for(opportunitylineitem ol:trigger.new){
        opportunitylineitem ole = new opportunitylineitem();
        ole.Id = ol.Id;
        ole.pickopp__c = pmap.get(ol.product2Id).pickprod__c;
    update updateolelist;

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.