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
tstrongtstrong 

Absolute Value of a Decimal Equation

I have a trigger using a variable that is the value of an equation that I need to get the absolute value of.  I can't seem to get the code to compile.  Here's the error I get and my code:

 

Error: Compile Error: Method does not exist or incorrect signature: ABS(Double) at line 32 column 32

 

 

Decimal DiscountDiff1 = null; Decimal DiscountDiff2 = null; Opportunity O = [select Id, Discount_Rollup__c, Max_Discount__c, Discount_Approved__c, SA_Discount__c, Account.Strategic_Account_Designation__c from Opportunity where Id = :OLI.OpportunityId LIMIT 1]; DiscountDiff1 = ABS (OLI.Discount__c - O.SA_Discount__c); DiscountDiff2 = ABS (O.SA_Discount__c - OLI.Discount__c);

 

OLI.Discount__c  & O.SA_Discount__c are both decimal (percent) fields.

 

 

 

Any help would be appreciated!

Best Answer chosen by Admin (Salesforce Developers) 
mikefmikef
You have to use Math.abs() or Math.ABS() not just ABS.

All Answers

mikefmikef
You have to use Math.abs() or Math.ABS() not just ABS.
This was selected as the best answer
m_roarkm_roark

Try changing your code to this:

 

DiscountDiff1 = (OLI.Discount__c - O.SA_Discount__c).abs();
DiscountDiff2 = (O.SA_Discount__c - OLI.Discount__c).abs();

 

The abs function has to be called against an instance of an decimal.  It isn't a static function.