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
Surender reddy SalukutiSurender reddy Salukuti 

Lightning_error

Hi Every one,
 i am new to lightning know i am learning Lightning.

actually i am invoking Apex class in Lightning

 i wrote the program

Apex class:
public class Lghtning_1 {
  @AuraEnabled
    public static string callme(){
        return 'surender reddy';
    } 
}
Lightning component:
<aura:component controller="Lghtning_1">
    <aura:attribute name="Result" type="string"/>
    <lightning:button label="submit" onclick="{!c.show}"/>
    
    Result:{!v.Result}
</aura:component>

Controll.js 
({
    show : function(component, event, helper) {
        
        var abc =component.get("c.callme");
        abc.setcallback(this,function(response){
            var state=response.getstate();
            if(state==="success"){
               var Result=response.getReturnvalue();
               component.set("v.Result",Result);
               }
        });
        $A.enqueueAction(abc);
        
    }
})
Applicatino call:
<aura:application >
    <c:Light_Apex/>
    </aura:application>
actually when i am execting this program i am getting error message like below

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

plese help me any one.

Thank you
Surender Reddy.

 
NagendraNagendra (Salesforce Developers) 
Hi Surender,

JavaScript is case sensitive. The function name which you have defined is not a valid one.

Please try the below code which works fine.
({
    show : function(component, event, helper) {
        
        var abc =component.get("c.callme");
        abc.setCallback(this,function(response){
            var state=response.getstate();
            if(state==="success"){
               var Result=response.getReturnvalue();
               component.set("v.Result",Result);
               }
        });
        $A.enqueueAction(abc);
        
    }
})
The function name which you are using in your code is abc.setcallback, but it should be abc.setCallback.

Hope this helps.

Kindly mark this as solved if the reply was helpful.

Thanks,
Nagendra



 
Yogeshwar TailorYogeshwar Tailor
Hi Surender,

Try below code for your javascript controller.
({
    show : function(component, event, helper) {
        
        var abc = component.get("c.callme");
        abc.setCallback(this,function(response){
            var state=response.getState();
            if(state === "SUCCESS"){
               var Result = response.getReturnvalue();
               component.set("v.Result",Result);
               }
        });
        $A.enqueueAction(abc);
        
    }
})

Marked the changes in bold letters. 

Please let me know if it will not workout.

Thanks,
Yogesh