You need to sign in to do that
Don't have an account?
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 ;
}
}
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 ; } }