Cannot change both ‘UnitPrice’ and ‘TotalPrice’ in update call

Recently, I was in need to update Sales Price (Unit Price) for OpportunityLineItem using Trigger. I wrote a small trigger on before insert and before update of OpportunityLineItem to update Sales Price.

It worked fine on insert however on update, even if user clicked on update button without changing any value, we were getting error Cannot change both ‘UnitPrice’ and ‘TotalPrice’ in update call.

Its Standard Salesforce behavior and seems in background platform tries to perform some calculation for Total Price which is Quantity * Sales Price. I was not able to get it working on before update. However, below two approach worked :

  1. Use Process builder to compute Unit Price as per formula. Process builder field update works after trigger so it went through.
  2. In after update trigger, create list of Opportunity Product to be updates and make explicit update call for all records which qualified for update.

Posted

in

by

Tags:


Related Posts

Comments

3 responses to “Cannot change both ‘UnitPrice’ and ‘TotalPrice’ in update call”

  1. Venkata Avatar
    Venkata

    Thank you for the valuable info.

  2. Natarajan Periyasamy Avatar
    Natarajan Periyasamy

    I’ve had this issue many times in the past and to resolve this I’ve just set TotalPrice = null and populate the unit price as required

  3. Pat Avatar
    Pat

    I am attempting to do exactly this and have worked on for a month. Unfortunately, I have no trigger experience and it has been baffling.

Leave a Reply to VenkataCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading