+ Start a Discussion
harsha vardhan vasa 9harsha vardhan vasa 9 

hi, getting error when i ran the component in application

Error:
This page has an error. You might just need to refresh it. Action failed: c:usercmp$controller$doInit [action.setcallback is not a function] Failing descriptor: {c:usercmp$controller$doInit}
Code :
Apexclass:
public with sharing class userdetails {
    @AuraEnabled
    public static user fetchuser(){
        user user1=new user();
        user1=[select id,username,firstname,lastname,email from user where id =:  userinfo.getUserId()];
        return user1;
    }
}

Component:
<aura:component controller="userdetails" >
    <aura:handler name="init" value="this" action="{!c.doInit}" />
    <aura:attribute name="usercmp"  type="user"/>
    <b> User details are below mentioned</b>
    <p> {!v.usercmp.email}</p>
    <p> {!v.usercmp.firstname}</p>
    <p> {!v.usercmp.lastname}</p>
    <p> {!v.usercmp.username}</p>
</aura:component>

Controller:
({
    doInit : function(component, event, helper) {
        var action = component.get("c.fetchuser");
        console.log("vachindhi");
        action.setcallback(this,function(response){
            var state = response.getstate();
            console.log(""+state);
            if(state==="SUCCESS"){
                 var storeresponse=response.getreturnvalue();
                component.set("v.usercmp",storeresponse);
            }
        });
        $A.enqueueAction(action);
    }
})
Lightining app to preview the out put:
<aura:application  extends="force:slds">
    <c:usercmp />
</aura:application>

please help where i went wrong.
Khan AnasKhan Anas (Salesforce Developers) 
Hi Harsha,

Greetings to you!

You need to use action.setCallback, getState, getReturnValue instead of action.setcallback, getstate, getreturnvalue
As lightning is based on aura framework which is a type of JavaScript and JavaScript is case sensitive so lightning is case sensitive. 

Use below code:
({
    doInit : function(component, event, helper) {
        var action = component.get("c.fetchuser");
        console.log("vachindhi");
        action.setCallback(this,function(response){
            var state = response.getState();
            console.log(""+state);
            if(state==="SUCCESS"){
                var storeresponse=response.getReturnValue();
                component.set("v.usercmp",storeresponse);
            }
        });
        $A.enqueueAction(action);
    }
})

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
Ajay K DubediAjay K Dubedi
Hi Harsha,
Javascript is case-sensitive.
action.setcallback is not a function because setCallBack should be:
action.setCallback

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi