• Dnyanesh Gawali
  • NEWBIE
  • 0 Points
  • Member since 2015

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

I have created following trigger for custom rollup summary.
but now i want to calculate sum of all orderItem on insertion of each new OrderItem. Now it only adding new value into existing rollup field.

Object Details :
Parent : Order
Child : OrderItem
Roll up field : Total_Pieces1__c (order field)
Summurised field : Pieces__c (OrderItem field)

trigger TotalPiecesSum on OrderItem (before update, before insert,before delete) {

list<Order> a = new list<Order>();
    set<id> OrderIDs= new set<id>();

if(trigger.isInsert || trigger.isBefore){
   for(OrderItem o : Trigger.new){
      OrderIDs.add(o.Orderid);
   }
   }

else if(trigger.isDelete){
     for(OrderItem o : Trigger.old){
         OrderIDs.add(o.Orderid);
     }
}
else 
      
     if(trigger.isUpdate){
     for(orderItem o: trigger.new){
        if(trigger.oldmap.get(o.id).Order!=o.Order){
            OrderIDs.add(o.OrderID);
            OrderIDs.add(trigger.oldmap.get(o.id).OrderID);
        }
    }
}
    
    AggregateResult[] groupedResults = [SELECT SUM(Pieces__c),OrderId FROM OrderItem where OrderId IN :OrderIDs GROUP BY OrderId ];
    system.debug('*******groupedResults **********'+groupedResults);     
    
    for(AggregateResult ar:groupedResults) {
        Id orid = (ID)ar.get('OrderId');
        system.debug('*******selected Oredr id **********'+orid);     
        Decimal count = (Decimal)ar.get('expr0');
            
        Order o1 = new Order(Id=orid);
        o1.Total_Pieces1__c= count;
        system.debug('*******Total_Pieces1__cOredr id **********'+count); 
        a.add(o1);
       }
   update a;
}
I want to integrate CCAvenue (online payment gateway solution provider) with Salesforce CRM.
Please share some steps or sample code of integration.

Thansk!
Hi,

I have created following trigger for custom rollup summary.
but now i want to calculate sum of all orderItem on insertion of each new OrderItem. Now it only adding new value into existing rollup field.

Object Details :
Parent : Order
Child : OrderItem
Roll up field : Total_Pieces1__c (order field)
Summurised field : Pieces__c (OrderItem field)

trigger TotalPiecesSum on OrderItem (before update, before insert,before delete) {

list<Order> a = new list<Order>();
    set<id> OrderIDs= new set<id>();

if(trigger.isInsert || trigger.isBefore){
   for(OrderItem o : Trigger.new){
      OrderIDs.add(o.Orderid);
   }
   }

else if(trigger.isDelete){
     for(OrderItem o : Trigger.old){
         OrderIDs.add(o.Orderid);
     }
}
else 
      
     if(trigger.isUpdate){
     for(orderItem o: trigger.new){
        if(trigger.oldmap.get(o.id).Order!=o.Order){
            OrderIDs.add(o.OrderID);
            OrderIDs.add(trigger.oldmap.get(o.id).OrderID);
        }
    }
}
    
    AggregateResult[] groupedResults = [SELECT SUM(Pieces__c),OrderId FROM OrderItem where OrderId IN :OrderIDs GROUP BY OrderId ];
    system.debug('*******groupedResults **********'+groupedResults);     
    
    for(AggregateResult ar:groupedResults) {
        Id orid = (ID)ar.get('OrderId');
        system.debug('*******selected Oredr id **********'+orid);     
        Decimal count = (Decimal)ar.get('expr0');
            
        Order o1 = new Order(Id=orid);
        o1.Total_Pieces1__c= count;
        system.debug('*******Total_Pieces1__cOredr id **********'+count); 
        a.add(o1);
       }
   update a;
}