Internal Error — when I pass a Javascript value to Apex

Is there some Salesforce equivalent of ? Here’s the files involved. I’ve pared them down to a simple case.
<aura:application >
    <c:cltTest />

<aura:component controller="svrTestController"
    <aura:handler name="init" value="{!this}" action="{!c.initComponent}"/> 

public with sharing class svrTestController {
    public static Integer doTest(String stringArgument, Integer integerArgument) {
        try {
            system.debug('stringArgument == \'cat\':');
            system.debug(stringArgument == 'cat');
            system.debug('integerArgument == 10:');  // line 11
            system.debug(integerArgument == 10);     // line 12
        } catch (Exception e) {
            system.debug('svrTestController caught exception.');
        } finally {
            system.debug('svrTestController is complete');
        return 10;
        // If you don't return something, Salesforce thinks it's a constructor, 
        // and objects that constructors can't be static.

    initComponent : function(cmp, event, helper) {

    cltDoTest : function(cmp) {
        var action = cmp.get('c.doTest');
            stringArgument: 'cat', 
            integerArgument: 12
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === 'SUCCESS') {
            } else {

When you run this, the log reads in part:

USER_DEBUG             [11]|DEBUG|integerArgument == 10:
FATAL_ERROR            Internal Error

The helper calls the server-side controller with a Javascript number of 12. The server-side controller interprets it as an Apex number. And the mechanism blows.

(I’ve just realized that there are no integers on the Javascript side. They are all “numbers”, floating point quantities. There’s part of the problem.)

We suspect the answer is to tell the Apex side what to expect. Something involving <apex:attribute>?


You’ll want to go log a case. It appears that the internal state of the parameter is screwed up. Using parseInt in the helper does not fix the problem. Interestingly, if you use Integer.valueOf in your apex code, the problem goes away:

system.debug(Integer.valueOf(integerArgument) == 10);

Alternatively, use the Decimal type. Our limited ability to view the underlying data will probably make it impossible for us “outsiders” to fix the problem. I’ve suggested two workarounds here, but R&D really needs to know about this so they can issue a Known Issue and get it fixed.

Edit: Doing anything at all with the parameter that involves an operator causes the error. For example, I tried sanitizing by adding 0:

Integer integerArgument2 = integerArgument+0;

Same result; it crashed when I tried to add 0. You have to use Integer.valueOf before it starts working like a normal Integer should.

Source : Link , Question Author : user2171796 , Answer Author : sfdcfox

Leave a Comment