-3

Apex class

public class Controller_Apex{
    @AuraEnabled
    Public static string callApexmtd(){
        return 'Amit kumar';
    }

}

component

<aura:component controller="Controller_Apex">
    <aura:attribute name="Result" type="string" />
    <lightning:button label="submit" onclick="{!c.show}" />

</aura:component>

controller

({
    show : function(component, event, helper) {
        var abc=component.get("c.callApexmtd");
        abc.setcallback(this,function(response)
        {
        var state=response.getstate();
        console.log('state :' + state);
        if(state === 'success'){
            var result=response.getreturnvalue();
            console.log('result' + result);
            component.set("v.result",result);
        }
        });
    $A.enqueueAction(abc);
}
})

Application

<aura:application extends="force.slds" >
    <c:component_apex />

</aura:application>

Error

This page has an error. You might just need to refresh it. Action failed: Capita_one:component_apex$controller$show [abc.setcallback is not a function] Failing descriptor: {Capita_one:component_apex$controller$show}

  • 2
    Making duplicate questions is considered rude here, and will tend to attract downvotes. Your questions don't appear to be attracting positive attention because it doesn't look like you've made a good-faith effort to understand the error you're getting or try to resolve the issue on your own. – Derek F Aug 8 '19 at 17:47
  • After a more thorough look at your questions, it does appear that they are slightly different (they're asking about different errors). This is an easy mistake to make when you just dump your code and error message and leave it at that. Descriptive titles and taking the time to explain your situation (like "I had a different error for this same code, but in a separate question") would help. – Derek F Aug 8 '19 at 17:55
2

All javascript methods are incorrect (case-sensitive) - setcallback, getstate, getreturnvalue

Corrected:

({
    show : function(component, event, helper) {
        var abc=component.get("c.callApexmtd");
        abc.setCallback(this,function(response) {
            var state=response.getState();
            console.log('state :' + state);
            if(state === 'success'){
                var result=response.getReturnValue();
                console.log('result' + result);
                component.set("v.result",result);
            }
        });
        $A.enqueueAction(abc);
    }
});

You can get the correct case-sensitive javscript methods from this example: https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/controllers_server_actions_call.htm

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.