• Akhilesh Pk
  • 0 Points
  • Member since 2023

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1

I want to do a Math.mod operation on a string (contains numeric values only) in an apex class. The maximul length of the string is 19.
Here is a sample value : 57901220028758151855

The problem is when I try to convert this to Long using Long.valueOf(string) , there is a type exception : invalid long
So I tried to get the long value using : Decimal.valueOf(string).longValue() , but when I check the value using System.debug  & it is = 2560987807629497007 , not the same as the original, so the mod result is also not correct.
I have to convert to Int, or Long because those are the only 2 types accepted by Math.mod(). and the max length of Integer is too small for these numeric strings.

The same operation is being performed in a validation rule using MOD (VALUE(string),divisor) with no problems.

Please help.


A Me

  • September 12, 2014
  • Like
  • 0