1

In my Org, there are two interdependent fields named Pacing and Pacing Notes.

The Pacing can't be set to Customer-Specific until the Pacing Notes field is empty. I am checking and validating this using the below validation rule.

AND(
ISPICKVAL(Pacing__c, 'Customer Specific'),
ISBLANK(Pacing_Notes__c)
)

These two fields exist at both Order and Order Item levels. And I have been updating the Pacing and Pacing notes from Order to all the Order line items under the Order, through my Apex code.

public static void updateLineItemRecord(Map<Id, Order> ordersListMap, Map<Id, String> csmArgMapVal, Map<Id, Date> startDateArgMapVal, Map<Id, Date> endDateArgMapVal, Map<Id, String> pacingArgMapVal, Map<Id, String> pacingNotesArgMapVal) {
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;
}
}

As the behavior of these two fields is the same at the Order Item Object too, I have added the same validation rule for Order Item Object also.

Now when someone sets the Pacing to "Customer-Specific" and the Pacing notes too to some text, both at the same time and saves it. my apex code tries to update the same in all dependent line items too. But all the time the Pacing is getting updated before the Pacing notes. As the Pacing notes field is still empty and my code is trying to set the Pacing to "Customer-Specific" the validation rule is firing at the Order Item level. And hence only the Pacing notes field is getting updated in all the line items and not the Pacing.

Can someone please let me know if there is a way through which at the Order level I can force the users to update and Save the Pacing notes first, and only then they can change the Pacing later, instead of updating both together? Or is there a way for me to handle this through my code?

2
  • If you could share the code you mention, I think that would be useful for those able to help with this. Commented May 11, 2021 at 11:48
  • @VictorL. I have added the code as you had asked for. Commented May 12, 2021 at 6:47

0

You must log in to answer this question.