1
<!----setCallBackCheck.cmp-->
<aura:component controller="LtngServerSideController">
    <aura:attribute name="accountName" type="String"/>
    <ui:outputText value="{!v.accountName}"/>
    <ui:button press="{!c.getName}" label="Get A Name"/>
</aura:component>

/*--------setCallBackCheckController.js------*/
({
    getName : function(component, event, helper) {
        var action = component.get("c.getAccountName");
        $A.enqueueAction(action);
        action.setCallback(this,function(response)){
            var status = response.getStatus();
            if(status === "SUCCESS"){
                component.set("v.accountName", response.getReturnValue());
            }
        }
})

/*--------setCallBackCheckController.apxc------*/
public class LtngServerSideController {
    @AuraEnabled
    public static string getAccountName(){
        List<account> accounts = [SELECT Id, Name FROM Account LIMIT 1];
        return accounts[0].Name;
    }
}

enter image description here

2
  • Please post full code to better assist Commented Aug 30, 2016 at 5:56
  • i have updated my code. Please have a look
    – RaJu
    Commented Aug 30, 2016 at 6:36

2 Answers 2

4

There are some issues with the client-side javascript controller that you wrote for your component.

Here is the corrected code:

({
    getName : function(component, event, helper) {
        var action = component.get("c.getAccountName");
        // your code as extra closing in the following line as well
        action.setCallback(this,function(response){
            // you should be using getState on result as getStatus doesn't exist in standard API
            var status = response.getState();
            if(status === "SUCCESS"){
                component.set("v.accountName", response.getReturnValue());
            }
        // your setCallback wasn't closed properly
        });
        // you enqueue the action even before it was setup
        $A.enqueueAction(action);
    }
})

I would recommend going through documentation on how to call apex methods from lightning component controllers.

Hope this helps.

0
5

Your callback has an empty function body, because the second parentheses closes the function body prematurely. Honestly, I'm surprised this compiled at all. It should look more like:

getMyContacts : function(cmp) {
    var action = cmp.get("c.getContacts");
    action.setCallback(this,function(response) {
        var status = response.getStatus();
        if(status === "SUCCESS"){
            cmp.set("v.contacts", response.getReturnValue());
        }
    });
}
2
  • I think one extra first bracket got included in the tailing end. Commented Aug 19, 2019 at 19:46
  • 1
    @ProlayChaudhury Yes, there was. I fixed it.
    – sfdcfox
    Commented Aug 19, 2019 at 19:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .