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

Simulate Max Roll-up Summary
Hello,
I am trying to simulate the MAX function on the roll-up summary fields with the trigger below but I am getting an error that my aggregate variable on line 18 is not recognized. Can any suggest how I can fix this to write the Maximum value of the custom field Max_Deliv__c on my OpportunityLineItem object to the related Opportunity object field Max_Deliv__c? Thanks,
I am trying to simulate the MAX function on the roll-up summary fields with the trigger below but I am getting an error that my aggregate variable on line 18 is not recognized. Can any suggest how I can fix this to write the Maximum value of the custom field Max_Deliv__c on my OpportunityLineItem object to the related Opportunity object field Max_Deliv__c? Thanks,
trigger UpdateMaxDeliv on OpportunityLineItem(before update) { Set <Id> Opp_Ids = new Set<Id>(); for (OpportunityLineItem oli1: trigger.new){ Opp_Ids.add(oli1.Id); } List<AggregateResult> maxDeliv = [SELECT Max(Max_Deliv__c) deliv FROM OpportunityLineItem]; for(AggregateResult aggOli : maxDeliv);{ List<Opportunity> opp1 = [SELECT Id, Max_Deliv__c FROM Opportunity WHERE Id in :Opp_Ids]; for(Opportunity o: opp1){ o.Max_Deliv__c = aggOli.get('deliv'); } update opp1; } }
No need to perform "Update" DML again since it is BEFORE Update event.