function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Praveen MeharPraveen Mehar 

i am getting an error => Cannot read property 'setCallback' of undefined,Please help.

Params1:
public class params1 {
    @AuraEnabled
    public static List<Account> accountthod(){
        List<Account> accounts=[select id,name,industry,rating,phone from Account limit 4];
        return accounts;
    }
}

pasasm.cmp
<aura:component controller="params1">
    <aura:attribute name="acclist" type="List"/>
    <aura:handler name="init" value="{!this}" action="{!c.invoke}"/>
    <aura:iteration items="{!v.acclist}" var="a">
        <p>{!a.name} &nbsp;&nbsp;&nbsp;{!a.industry} &nbsp;&nbsp;&nbsp;{!a.rating} &nbsp;&nbsp;&nbsp;{!a.phone}</p>
    </aura:iteration>
</aura:component>

parasmController.js
({
    invoke : function(component, event, helper) {
        var action=component.get("v.accountthod");
        action.setCallback(this,function(response){
            console.log("invoked");
            var state=response.getState();
            if(state==='SUCCESS'){
                console.log('Operation successfull');
                component.set("v.acclist",response.getReturnValue());
            }else{
                console.log('Operation failed');
            }            
        });
        $A.enqueueAction(action);
    }
})

parasmap.app
<aura:application extends="force:slds">
    <c:parasm />
</aura:application>
Best Answer chosen by Praveen Mehar
Maharajan CMaharajan C
Hi Praveen,

You have to use c.MethodName in below line not v.Methodname:
var action=component.get("v.accountthod");  ==>   var action=component.get("c.accountthod");

Updated JS:
 
({	
    invoke : function(component, event, helper) {	
        var action = component.get("c.accountthod");	
        action.setCallback(this, function(response) {	
            var state = response.getState();	
            if (state === "SUCCESS") {	
                console.log('Operation successfull');	
                component.set("v.acclist",response.getReturnValue());	
            }	
            else{	
                console.log('Operation failed');	
            } 	
        });	
        $A.enqueueAction(action);	
    }	
})


Updated Component : ( use the caps in starting letter of field name to refer the field values like below): 
name ==> Name , industry ==> Industry, rating ==>Rating, phone ==> Phone
 
<aura:component implements="flexipage:availableForAllPageTypes" access="global" controller="params1" >
    <aura:attribute name="acclist" type="List"/>
    <aura:handler name="init" value="{!this}" action="{!c.invoke}"/>
    <aura:iteration items="{!v.acclist}" var="a">
        <p>{!a.Name} &nbsp;&nbsp;&nbsp;{!a.Industry} &nbsp;&nbsp;&nbsp;{!a.Rating} &nbsp;&nbsp;&nbsp;{!a.Phone}</p>
    </aura:iteration>
</aura:component>


Thanks,
Maharajan.C

 

All Answers

Maharajan CMaharajan C
Hi Praveen,

You have to use c.MethodName in below line not v.Methodname:
var action=component.get("v.accountthod");  ==>   var action=component.get("c.accountthod");

Updated JS:
 
({	
    invoke : function(component, event, helper) {	
        var action = component.get("c.accountthod");	
        action.setCallback(this, function(response) {	
            var state = response.getState();	
            if (state === "SUCCESS") {	
                console.log('Operation successfull');	
                component.set("v.acclist",response.getReturnValue());	
            }	
            else{	
                console.log('Operation failed');	
            } 	
        });	
        $A.enqueueAction(action);	
    }	
})


Updated Component : ( use the caps in starting letter of field name to refer the field values like below): 
name ==> Name , industry ==> Industry, rating ==>Rating, phone ==> Phone
 
<aura:component implements="flexipage:availableForAllPageTypes" access="global" controller="params1" >
    <aura:attribute name="acclist" type="List"/>
    <aura:handler name="init" value="{!this}" action="{!c.invoke}"/>
    <aura:iteration items="{!v.acclist}" var="a">
        <p>{!a.Name} &nbsp;&nbsp;&nbsp;{!a.Industry} &nbsp;&nbsp;&nbsp;{!a.Rating} &nbsp;&nbsp;&nbsp;{!a.Phone}</p>
    </aura:iteration>
</aura:component>


Thanks,
Maharajan.C

 
This was selected as the best answer
Maharajan CMaharajan C
<aura:application extends="force:slds">
    <c:pasasm />
</aura:application>
Praveen MeharPraveen Mehar

Hi Maharajan,

Thanks for the resply, now its working fine.