+ Start a Discussion
sekhar passamsekhar passam 

This page has an error. You might just need to refresh it. Action failed: sekh:accountcom$controller$getac [action.setcallback is not a function] Failing descriptor: {sekh:accountcom$controller$getac}



My apex class\\
public with sharing class accountobj {
    @AuraEnabled
    public static list<account> getAccountss(){
        list<account> accountss=[select id,name,phone,billingcity from account limit 100];
        return accountss;
    }


}


My component is 
<aura:component controller="accountobj">
    <aura:attribute name="accountss" type="account[]"/>
    <ui:button label="Get accounts" press="{!c.getac}"/>
     <aura:iteration var="account" items="{!v.accountss}">
        <p>{!account.name}:{!account.phone}</p>
    </aura:iteration>
    
</aura:component>

my controller js

({
    getac:function(rec) {
        var action=rec.get("c.getAccountss");
        action.setcallback(this,function(response){
      
        var state = response.getState();
        if(state === "SUCCESS"){
            rec.set("v.accountss",response.getReturnValue());
        }
                           });
    $A.enqueueAction(action);    
    }
})
 
Best Answer chosen by sekhar passam
GhanshyamChoudhariGhanshyamChoudhari
CMP
 
<!--  capitalize Name and  Phone-->

 <p>{!account.Name}:{!account.Phone}</p>

Controller 
({
    getac:function(rec) {
        var action = rec.get("c.getAccountss");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
               rec.set("v.accountss",response.getReturnValue());    
            }  
        });
        $A.enqueueAction(action);
    }
})



 

All Answers

Raj VakatiRaj Vakati
Javascript is case sensitive .. use the below code setCallback is the correct name
 
({
    getac:function(rec) {
        var action=rec.get("c.getAccountss");
        action.setCallback(this,function(response){
      
        var state = response.getState();
        if(state === "SUCCESS"){
            rec.set("v.accountss",response.getReturnValue());
        }
                           });
    $A.enqueueAction(action);    
    }
})



 
GhanshyamChoudhariGhanshyamChoudhari
CMP
 
<!--  capitalize Name and  Phone-->

 <p>{!account.Name}:{!account.Phone}</p>

Controller 
({
    getac:function(rec) {
        var action = rec.get("c.getAccountss");
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
               rec.set("v.accountss",response.getReturnValue());    
            }  
        });
        $A.enqueueAction(action);
    }
})



 
This was selected as the best answer