I have created a Trigger on Order object. There is a field called pacing in both Order and Order product Objects. When the Pacing is updated in the Order, I am updating the Pacing field in the Order Products too that are related to that particular Order, using the below code.
if(ord.Pacing__c != oldOrd.Pacing__c) {
changedPacing.put(ord.Id, ord);
pacingMapVal.put(ord.Id, oldOrd.Pacing__c);
}
if(changedPacing.size() > 0) {
OrderToOrderProductAutomation.updateLineItemRecord(changedPacing, null, null, null, pacingMapVal);
}
if(pacingArgMapVal != null && pacingArgMapVal.size() > 0) {
List<OrderItem> updates = new List<OrderItem>();
for (OrderItem detail : [SELECT Id, OrderId, Customer_Success_Manager__c, Line_Item_Start_Date__c, Line_Item_End_Date__c, Pacing__c
FROM OrderItem
WHERE OrderId IN :ordersListMap.keySet()]) {
Order oso = ordersListMap.get(detail.OrderId);
String pacing = oso.Pacing__c;
if (detail.Pacing__c == pacingArgMapVal.get(detail.OrderId)) {
detail.Pacing__c = pacing;
updates.add(detail);
}
}
update updates;
}
I have created Process builder which creates a record in a custom Object called History__c whenever the a particular 6 fields are updated in Order, including the Pacing, by calling a flow using process builder.
Now whenever I am updating the pacing. 3 identical records are getting created in History Object. When I comment my trigger code, one History record is getting created as expected. Can anyone please let me know why this is happening and How can I sort this out.
Note: There are 3 roll-up summary fields in Order Object, to the Order Product object.
This is how my process builder conditions looks like.