Skip to main content
Hello, 

I am trying to rollup a custom field "Product_Alert_Message" from the OpportunityItemLine to an Opportunity field "Product_Alerts_Roll_up__c".

I have the below Apex Class:

global with sharing class OppProductReqRollupTriggerHandler 

{

    global static void MainProcess(set<id> OpportunityIds)

    {

        //Create List to hold final concatenated result

        List<Opportunity> OpportunityList = new List<Opportunity>();

        

         //Create list to Children that have Parents within Parent Set.

        List<Opportunity> Opportunity = [Select Id,Product_Alerts_Roll_up__c, (SELECT Id,   OpportunityLineItem.Product_Alert_Message__c from OpportunityLineItem) from Opportunity where Id in :OpportunityIds];

 

        //Loop through List result to build concatenated string and add to sampleList

        for (Opportunity s:Opportunity)

        {

           String concatenateString = '';

              for (OpportunityLineItem sp: s.OpportunityLineItem)

              {

                if(sp.OpportunityLineItem__r.Product_Alert_Message__c <> null)

                {

                    concatenateString += sp.OpportunityLineItem__r.Product_Alert_Message__c + ';';

                }

              }

              s.Product_Alerts_Roll_up__c = concatenateString.replace('null','').removeEnd(';');

              OpportunityList.add(s);

        }

 

        //Update Parent object with concatenated string

        update OpportunityList;

    }

}

 but it's giving me the below errors:

Error: Compile Error:

OpportunityLineItem.Product_Alert_Message__c from OpportunityLineItem) from Opportunity

^

ERROR at Row:1:Column:102

Didn't understand relationship 'OpportunityLineItem' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 9 column 41.

Can someone help me with this?

Thanks,
8 answers
  1. Feb 8, 2019, 9:50 AM
    Also there is no need to use OpportunityLineItem.Product_Alert_Message__c if it is a field on OpportunityLineItems. You can just use Product_Alert_Message__c in inner SOQL.
0/9000