0

I am facing a weird issue of Salesforce calling infinite times the Server side Action from the Lightning component. Has anyone faced a similar issue?

I am pasting the code for your reference.

<lightning:button variant="brand" label="Save" title="Save" onclick="{!c.saveProductToQuote}"/>

The Javascript controller for the same :

saveProductToQuote : function(component, event, helper) {
    //alert('Inside saveProductToQuote');
    helper.saveProductToQuote(component, event, helper); 
}

The Javascript Helper is :

saveProductToQuote : function(component, event, helper) {
    var action = component.get("c.saveProductToQuote");
    var prod = JSON.stringify(component.get("v.selectedPrdRec"));
    console.log('Inside the Helper'+JSON.stringify(prod));
    action.setParams({
        "prod" : prod
    });
    action.setCallback(this,function(a){
        //get the response state
        var state = a.getState();
        //check if result is successfull
        if(state == "SUCCESS"){
            var result = a.getReturnValue();
            console.log(result);
        } else if(state == "ERROR"){
            alert('Error in calling server side action');
        }
    });
    $A.enqueueAction(action);
}

And the Apex controller Method is :

@AuraEnabled
public static boolean saveProductToQuote(String prod){
    system.debug(prod);
    return true;
}

The two console.log statements in the Helper prints the details infinitely and my browser crashes. And no Apex debug log for calling server side action is logged.

Thanks for the help.

3

The server side and client side controller method names should be different. change the name of server side method saveProductToQuote

From 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.

  • Hi @RedDevil Thanks a lot, I don't know how I missed sighting the issue of naming both the Apex Method name and Helper name same. – Abhiram Sheshadri Jun 6 '18 at 7:25
  • No worries. Happy to help! – RedDevil Jun 6 '18 at 7:26
  • 2
    @RedDevil helper method names and server side name can be same it don't cause any issues.only component controller name and apex method name should be different. – vignesh Jun 6 '18 at 7:39

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.