function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rbuchananrbuchanan 

getting error about Arithmetic expressions must use numeric arguments

Hi.  I'm attempting to write my first APEX code in the form of a trigger.  I have a custom field on the Opportunity Product page called "Refurbished__c".  It's a checkbox.  If the salesperson checks that box on the item he's adding to the opportunity, I want the list price to automatically get a 65% discount and show that calculated amount on the same page that he checked the box. 

My code so far is this, but I get an error on line 3 just after the "=" sign when I try to compile (error message in subject line above)  Any help would be much appreciated!   Thanks.

 

trigger Refurbished_Checked on OpportunityLineItem (After Update) {
    if (OpportunityLineItem.Refurbished__c) {
        OpportunityLineItem.ListPrice = OpportunityLineItem.ListPrice * 0.35 ;
  } else {
        OpportunityLineItem.ListPrice = OpportunityLineItem.ListPrice ;
  }
}

aalbertaalbert

OpportunityLineItem is not a valid object. You need to iterate through the Trigger.new array. I also recommend changing to a "before update" trigger so you can more efficiently change the ListPrice field value. Lastly, I commented out the else part of the if/else statement since it didn't do anything to the ListPrice value. 

 

 

Here is a revised version to show you what I am referring to:

 

 

trigger Refurbished_Checked on OpportunityLineItem (Before Update) { for(OpportunityLineItem oli: Trigger.new){ if (oli.Refurbished__c==true) { oli.ListPrice = oli.ListPrice * 0.35 ; } //else { // oli.ListPrice = OpportunityLineItem.ListPrice ; } }

 

 

 

JimRaeJimRae
In addtion to the excellent suggestions above, you might also consider checking to make sure the list price is not null, as that would cause an exception to occur.
aalbertaalbert
Thinking through this some more, you could probably avoid using Apex, and use Workflow Rules/Field Updates to accomplish the same functionality.
rbuchananrbuchanan
Thanks!   I appreciate the responses.  Think I'll go with the workflow/field update approach.