You need to sign in to do that
Don't have an account?

Roll Up Opportunity Product Name up to Opportunity
I'm trying to display opportunity product names to opportunity custom field. The trigger is working fine but it displays only last record name. eg. If I have 4 products related to opportunity, it display 4th product name and not display the first three. I would like to display each product name with ',' in between. here is my code. Any idea what need to be added in order to display all related products name.
Trigger OppProdLine on Opportunity (before update) { list<opportunity> sl = trigger.new; list<opportunityLineItem> slnu = new list<opportunityLineItem>([select id ,product2.name, opportunityId from opportunitylineitem where opportunityId =: trigger.new[0].id]); string productName=''; for(opportunityLineItem opp : slnu){ productName = opp.product2.name; } for(Opportunity opp : trigger.new){ opp.Opportunity_Prod__c = productName; } }
The concatenation operator is missing at line no 11. Below is the corrected code.
Note - I see your trigger is no bulkified which is in best coding guideline from SFDC.