You need to sign in to do that
Don't have an account?
TJMeadows
Error Updating Order in Update Trigger
Hello all,
I'm running into an error that just doesn't make sense to me. I have a trigger on OrderItem that evaluates related payments to an order to determine if it is paid off. The error claims that a change to the order currency is happening, but that is not the case. I've debugged the before and after object maps to verify that CurrencyIsoCode is unchanged.
Here is the trigger handler:
and the erroring method:
Thanks for any insight you all can give
I'm running into an error that just doesn't make sense to me. I have a trigger on OrderItem that evaluates related payments to an order to determine if it is paid off. The error claims that a change to the order currency is happening, but that is not the case. I've debugged the before and after object maps to verify that CurrencyIsoCode is unchanged.
Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OrderItemTrigger: execution of AfterInsert
caused by: System.DmlException: Update failed. First exception on row 0 with id 8013D0000009C8hQAE; first error: FIELD_INTEGRITY_EXCEPTION, You can't edit the order currency when the order has order products.: Contract Currency: [CurrencyIsoCode]
caused by: System.DmlException: Update failed. First exception on row 0 with id 8013D0000009C8hQAE; first error: FIELD_INTEGRITY_EXCEPTION, You can't edit the order currency when the order has order products.: Contract Currency: [CurrencyIsoCode]
Here is the trigger handler:
private void evaluatePaidOffStatus(List<OrderItem> orderItems) { if (shouldRun('evaluatePaidOffStatus')) { methodRunMap.put('evaluatePaidOffStatus', false); Set<Id> orderIds = new Set<Id>(); for (OrderItem orderItem : orderItems) { orderIds.add(orderItem.OrderId); } OrderTransferService.evaluateOrderPayments(orderIds); } }
and the erroring method:
public static void evaluateOrderPayments(Set<Id> orderIds) { Order[] orders = [select Id, Grand_Total__c, Paid_Off__c, (select Id, pymt__Amount__c from Payments__r) from Order where Id in :orderIds];// and Type != 'EDI']; for (Order order : orders) { Decimal amountPaid = 0.00; for (pymt__PaymentX__c payment : order.Payments__r) { amountPaid += payment.pymt__Amount__c; } order.Paid_Off__c = amountPaid >= order.Grand_Total__c; } update orders; }
Thanks for any insight you all can give
Ref:
https://help.salesforce.com/articleView?id=fields_about_roll_up_summary_fields.htm&type=0
https://trailhead.salesforce.com/en/modules/point_click_business_logic/units/roll_up_summary_fields
I'll look in to what that implementation would look like, but that still doesn't provide insight as to why this error is being thrown.