• Alexandra Cuyvers
  • NEWBIE
  • 5 Points
  • Member since 2019
  • Global CRM Administrator
  • Michelman SARL

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
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,
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,