Trying to write trigger on Order item .I have created new field called discount.I have to perform formula using trigger on TotalPrice(TotalPrice=Discount*TotalPrice).I am not able to access TotalPrice hence getting this error "Innvalid field TotalPrice for SObject OrderItem " Not understanding how to access TotalPrice fields .

 trigger Totalprice on OrderItem (after insert,after update)  {
      if(trigger.isafter && trigger.isupdate){
           for(OrderItem oi : trigger.new) {
               Oi.TotalPrice=  Oi.Discount__c*Oi.TotalPrice;

The TotalPrice field is not available in OrderItem object it is being calculated

OrderItem.TotalPrice = OrderItem.UnitPrice * OrderItem.Quantity

so query for the quantity and unitprice and use above formula.

Hope this helps you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.