You need to sign in to do that
Don't have an account?

Math.mod Method doesn't work with variables as arguments.
Hi, I'm trying to develop a trigger that checks a document number format (validation digit), so I need to use the Math.mod method in ApexCode but I found it seems to reject the Double variable as Argument. Here is the related code:
trigger AccountDigitoVerificacion_tgr on Account (before insert, before update) { if (Trigger.new.size() > 1 ) { // bulk process only }else{ Integer DIV = 0; Double DocNumber = 0; Boolean Calculate = false; for (Account MyAccount : System.Trigger.new) { if(MyAccount.RecordTypeId=='012T0000000CiygIAC' || MyAccount.RecordTypeId=='012T0000000CissIAC'){ DocNumber = MyAccount.Document_Number__c; if(System.Trigger.isInsert){ Calculate = true; }else{ if(System.Trigger.isUpdate){ for (Account MyAccountOld : System.Trigger.old) { if(MyAccount.Document_Number__c!=MyAccountOld.Document_Number__c){ Calculate=true; } } } } if(Calculate==true){ // Calculates the validation digit Integer M=0; Integer S=1; for(;DocNumber!=0;DocNumber=Math.floor(DocNumber/10)){ // Here is where the code validator shows an Error : S+Math.mod(DocNumber, 10) S=Math.mod((S+Math.mod(DocNumber, 10)*(9-Math.mod(M++,6))), 11); } MyAccount.Validation_Digit__c = S?S-1:'k'; } } } } }
I tried inserting a value in the first argument directly and it works, but, when I replace it by a variable, it shows the following error (NO MATTER the value source):
"Method does not exist or incorrect signature: Math.mod(Double, Integer)".
Any suggestion to correct it or replace that function??
Thanks,
WILMER
All Answers
Thanks wilmer. This is exactly what i'm looking for.
You're welcome!
It is so nice to see that things I've shared 5 years ago are still useful to others.