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
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>();
    map<Id,product2> pmap = new map<Id,product2>([select Id,pickprod__c from product2 where Id IN :Ids]);
        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.