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
NevDevNevDev 

trigger to update opportunity field with product custom field

Can anyone help me with a trigger that updates an Opportunity custom field "Quotation_ID_c" with the values from the Opportunity Product Line Item Custom Field "Quotation_ID_c"?
vishnu Rvishnu R
Hi Nevin,,

try this...
trigger triggeropportunitylines on OpportunityLineItem (after update,after insert) {
list<id> oppids=new list<id>();
list<opportunity> oppnames=new list<opportunity>();
for(OpportunityLineItem c:trigger.new){
oppids.add(c.opportunityId);
}
system.debug('>>>>'+oppids);
List<opportunity> opps=new List<opportunity>([select id, shobithapp__Quotation_ID__c,(select id,shobithapp__Quotation_ID__c from OpportunityLineItems) from opportunity where Opportunity.Id in:oppids]);
string n='';
for(opportunity o:opps){
for(OpportunityLineItem o1:o.OpportunityLineItems){
n=n+o1.shobithapp__Quotation_ID__c+'::' ;
}
o.shobithapp__Quotation_ID__c=n;
oppnames.add(o);
}
update oppnames;
}

mark this as best answer if it helps you...
thanks