+ Start a Discussion
Gage Staruch 9Gage Staruch 9 

Concatenate opportunity products and roll them into a field

Hi everyone!

I am trying to build a trigger that automatically updates a field on the opportunity with a list of all the opportunity products. This is what I have so far, but it doesn't seem to be working :/ 
trigger OpportunityProducts on Opportunity (after update, after insert, before update) {
    for (Opportunity O: Trigger.new)
        List<Opportunity> opps = new list<Opportunity>([Select Id, (Select Id, name From OpportunityLineItems) From Opportunity]);
        If (O.Name != null ) 
        String OppString = String.join(opps, '');{
        String OppString = O.Products_Listed__c;{

Any help is appreciated!
AbhishekAbhishek (Salesforce Developers) 
Hi Gage,

Try the code as mentioned in the below blog,


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.