3

So I have many of these, 10 to be exact and three won't execute, they are all the exact same and I feel I have been going around in circles for hours. I have noticed that if an apex method ends with the letter "s" that it won't execute the callback for some reason. Don't know if this is something everyone experiences or just me. But I have tried renaming the apex methods, the variables, everything i can think of. Below i can get through propTen just fine and it does what its suppose to do, but it will only get to alert 4 of propTwentyFive. And i can't figure out why it wont execute the callback.

Any thoughts?

 grayButtons: function(component, event, helper)
    {
        helper.PropTen(component, event);
        helper.PropTwentyFive(component,event);

    },

PropTen: function(component, event)
    {
        var action = component.get("c.PropTenPercent");
        var myId = component.find("accordion").get("v.activeSectionName");
        action.setParams({"ten" : myId});
        action.setCallback(this, function(response)
         {
           var state = response.getState();
           if(state === "SUCCESS")              
           {
            var storeResponse = response.getReturnValue();
               if (response.getReturnValue().length != 0) 
                {
                    component.set("v.isDisabled11", "false");
                } else 
                {
                    component.set("v.isDisabled11", "true");   
                }

            } else 
            {
               alert("Unknown error");
            }

       });
        $A.enqueueAction(action);       
      },

    PropTwentyFive: function(component, event)
    {
        alert('1');
        var action = component.get("c.PropTwentyFive");
        alert('2');
        var myId = component.find("accordion").get("v.activeSectionName");
        alert(myId);
        action.setParams({"twentyFive" : myId});
        alert('4');
        action.setCallback(this, function(response)
         {
             alert('5');
           var state = response.getState();
           if(state === "SUCCESS")              
           {
            var storeResponse = response.getReturnValue();
               if (response.getReturnValue().length != 0) 
                {
                    component.set("v.isDisabled12", "false");
                } else 
                {
                    component.set("v.isDisabled12", "true");   
                }

            } else 
            {
               alert("Unknown error");
            }

       });
        $A.enqueueAction(action);       
      },

 @AuraEnabled   
        public static List <Opportunity> PropTenPercent(String ten) 
        {
             List <opportunity> hipdeals = new List<opportunity>();      
             String otherattr = ten;
             hipdeals = [[select Ownership__c,Name,NextStep
                        from opportunity where recordtype.name in ('Test') and Name =: otherattr and Probability = 10];
             return hipdeals;
        }

        //25% deals
        @AuraEnabled  
        public static List <Opportunity> PropTwentyFive(String twentyFive) 
        {
            List <opportunity> hipdeals = new List<opportunity>();
            String otherattr = twentyFive;
            hipdeals = [select Ownership__c,Name,NextStep
                        from opportunity where recordtype.name in ('Test') and Name =: otherattr and Probability = 25];  

            return hipdeals; 
        }    

0
4

From this documentation,

Use unique names for client-side and server-side actions in a component. A JavaScript function (client-side action) with the same name as an Apex method (server-side action ) can lead to hard-to-debug issues. In debug mode, the framework logs a browser console warning about the clashing client-side and server-side action names.

Reason:

Lightning is MVC model framework. In view (HTML/COMPONENT) you can get the value of an attribute by using v. and you can get the reference of javascript method by using c. and again in javascript, you need to get the reference to apex method definition by using same c.. Here is what is interesting, aura_prod library internally gets confused when both javascript method (controller/helper) and apex method names are same as they both are referenced by c.!!

Here is another documentation where its clear that salesforce agrees that they made mistake while writing the framework:

“Wait a minute. Are you telling me we have c the client-side controller, c the default namespace, and c the server-side controller, all in Aura components?”

Well, in a word, yes. Deep breaths.

Look, we’ll be honest with you. If we had it all to do over again, we might have made some different choices. While the choices we made weren’t accidents, three “c”s is definitely an opportunity for confusion. We get confused too!

But as they say, it is what it is. Forewarned is forearmed. Now you know.

0

Update: The solution was changing PropTwentyFive to PropTwentyFivePercent or simply Property. I'm not entirely sure on naming conventions but it appears that you can't name an apex method the same name as the helper that is calling it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.