• 4i Apps
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Hi,

I have a lookup relationship between Quote and Order. I have a field on Order called Milestone_Amount__c that has to rollup to a field on Quote called Cumulative_Order_Value__c, after insert, after update, after delete, after undelete.

Requesting assistance to correct the below piece of code:
 
trigger orderMaster on Order (after delete,after update, after undelete) {
 list<Quote> quotelist = new List<Quote>();
set<id> quoteIDs = new set<id>();
if(trigger.isDelete){
    for(Order orderItem : Trigger.old){
        quoteIDs.add(orderItem.QuoteId);
     }
}
else if(trigger.isUnDelete){
     for(Order orderItem : Trigger.new){
     quoteIDs.add(orderItem.QuoteId);
      }
}
else if(trigger.isUpdate){
     for(Order orderItem : trigger.new){
if(trigger.oldmap.get(orderItem.id).Quote!=orderItem.Quote){
quoteIDs.add(orderItem.QuoteId);
quoteIDs.add(trigger.oldmap.get(orderitem.id).quoteId);
}
}
}
AggregateResult[] groupedResults = [SELECT SUM(Milestone_Amount__c) FROM Order where QuoteId IN :quoteIDs];
   for(AggregateResult ar:groupedResults) {
        Id custid = (ID)ar.get('Quote.Id');
        Integer count = (INTEGER)ar.get('expr0');
        Quote cust1 = new Quote(Id=custid);
        cust1.Cumulative_Order_Value__c = count;
        quotelist.add(cust1);
     }
     update quotelist;
}

 
  • September 01, 2016
  • Like
  • 0
I have two standard objects Quote and Order. There exists a lookup relationship between these two. I have a field on Order called Milestone_Amount__c and a field on Quote called Cumulative_Order_Value__c.

On insert, this field on Order will be blank. But I need an after update, after delete, after undelete trigger to rollup the sum of this field on order to the cumulative field on quote. Can someone help me?

I'm not very familiar with Apex Code development.

Thanks