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
Michal KozakMichal Kozak 

Internal Salesforce.com Error for @auraEnabled integer operation

Hi, I tried to report this bug to salesforce, but was redirected here.
This is very likely internal salesforce issue.
When you try to do any operation with integer received from lightning component (@AuraEnabled), you got 
FATAL_ERROR|Internal Salesforce.com Error
 
public with sharing class TestController2 {
    @AuraEnabled
    public static integer getTestResult(integer pageNumber) {
        return pageNumber + 1;
    }
}


Full log included:
34.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
23:30:39.143 (143052245)|EXECUTION_STARTED
23:30:39.143 (143081946)|CODE_UNIT_STARTED|[EXTERNAL]|01pU0000001YzfB|TestController2.getTestResult
23:30:39.143 (143501666)|METHOD_ENTRY|[1]|01pU0000001YzfB|TestController2.TestController2()
23:30:39.143 (143599706)|SYSTEM_MODE_ENTER|false
23:30:39.143 (143634027)|SYSTEM_MODE_EXIT|false
23:30:39.143 (143644512)|METHOD_EXIT|[1]|TestController2
23:30:39.144 (144047168)|FATAL_ERROR|Internal Salesforce.com Error
23:30:39.144 (144066440)|CUMULATIVE_LIMIT_USAGE
23:30:39.144 (144066440)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

23:30:39.144 (144066440)|LIMIT_USAGE_FOR_NS|Vendavo|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

23:30:39.144 (144066440)|CUMULATIVE_LIMIT_USAGE_END

23:30:39.144 (144134140)|CODE_UNIT_FINISHED|TestController2.getTestResult
23:30:39.147 (147174875)|EXECUTION_FINISHED

Note that system.debug('pageNumber: ' + pageNumber); works. But all other integer operations fail.
Please advise how to circumvent this issue.
Best Answer chosen by Michal Kozak
Michal KozakMichal Kozak
Workaround, that works:
public static integer getTestResult(string pageNumber) {
        integer tmp = integer.valueof(pageNumber);
        return tmp + 1;
    }

change the parameter to string and convert its value in the code.

All Answers

Michal KozakMichal Kozak
Workaround, that works:
public static integer getTestResult(string pageNumber) {
        integer tmp = integer.valueof(pageNumber);
        return tmp + 1;
    }

change the parameter to string and convert its value in the code.
This was selected as the best answer
Rufus RodenRufus Roden
This is still an issue 12 months later.  I've come across it but with Long as the parameter type.  Salesforce support were helpful and told me the meaning of the internal error was "java.math.BigDecimal cannot be cast to java.lang.Long".  In other words, and this to me is terrifying, the method had managed to start to be executed even though the parameter, which was defined as a Long, was in reality a java BigDecimal.  It was only when the param was being accessed that any attempt at the conversion was made!

If @AuraEnabled methods don't support Long or Integer parameters then that should be flagged in the editor and not allow you to save.  If it is allowed then the correct conversion should be done before enter the method.

By the way, an alternative solution to changing the type to string, is to change it to Decimal.  At least that way the calling code can maintain the belief that it's somewhat numeric related.
Saku ErlaSaku Erla
The easiest way to fix this - no string parsing, no extra variables:
@AuraEnabled
global static void doThing(Integer myInt) {
    myInt = Integer.valueOf(myInt);
    // ...
}

By the way, this is a ridiculous problem and pretty astonishing for a 25,000 employee company to leave it unfixed for so long. And what the heck is up with type checking in Apex?! Are you running on PHP?
Scott Morrison 33Scott Morrison 33
Still an issue
Scott Morrison 33Scott Morrison 33
Pretty sure it's still a java backend 
SkiesnPiesSkiesnPies
Wow, concerning that this bug still exists. Just fought with some code for a couple of hours before finding this thread. Thanks for posting the workaround. V.poor that this wasn't fixed though. 
Abhishek-TripathiAbhishek-Tripathi
This is still killing. They should mention this in docs, if not going to change in near future.. 
EJWEJW
Why does this bug still exist almost 3 years later?  We have to add workarounds in code to use a simple integer paramter in a controller?
Naveen IlaNaveen Ila
There is a difference, when we are sending the parameters here. 

{
    "pageNumber" : "1"  // send this as string, Then apex controller might generates an error, here in this case
}


{
     "pageNumber": 1 // passes value as integer to the controller. So won't get any error. 
}


If you have a string value, we can use parseInt() function in JavaScript