0

Uncaught error in actionCallback : Unable to find 'getExpenses' on 'compound://srinivasareddys.form'.

I'm getting this error. Kindly let me know where i check code.

server-side controller

public with sharing class ExpenseController { 
    @AuraEnabled public static List<Expense__c> getExpense(){
        return [SELECT id, Name, Amount__c, Client__c, Date__c, Reimbursed__c, CreatedDate FROM Expense__c]; 
    } 
}

client-side controller

({ 
   doInit : function(component, event, helper) {
       //Update expense counters 
       helper.getExpenses(component);
   },//Delimiter for future code 
})
4
  • public with sharing class ExpenseController { @AuraEnabled public static List<Expense__c> getExpense(){ return [SELECT id,Name,Amount__c,Client__c,Date__c,Reimbursed__c,CreatedDate FROM Expense__c]; } }
    – SSR
    Commented Oct 14, 2015 at 4:31
  • ({ doInit : function(component, event, helper) { //Update expense counters helper.getExpenses(component); },//Delimiter for future code })
    – SSR
    Commented Oct 14, 2015 at 4:31
  • where am change the code kindly let me know asap
    – SSR
    Commented Oct 14, 2015 at 4:32
  • Based on this question, and the answer, and the long back and forth on the answer, I would strongly recommend you spend some time learning lightning components. There is a Trailhead module you can go through that should help with some of these basic questions you are struggling with.
    – pchittum
    Commented Oct 18, 2015 at 23:39

2 Answers 2

1

The problem here is that the method getExpense() is not located in the client-side helper, but rather in an apex class. If you want to call this method, you can use this general pattern:

({ 
   doInit : function(component, event, helper) {
        var action = component.get("c.getExpense");
        action.setCallback(this,function(response){
                if (response.getState() === "SUCCESS"){
                    // do something with the expense records
                }
            }
        );
        $A.enqueueAction(action);
    }, 
    createExpense : function(component, event, helper){
        // do something
    }
})

The Lightning Components Developer's Guide has more information on this topic that you might also find useful.

18
  • i added given code after reload the page im getting below error
    – SSR
    Commented Oct 14, 2015 at 4:54
  • Uncaught error in $A.run() : Unable to find 'createExpense' on 'compound://srinivasareddys.form'. Kindly let me know @martin .
    – SSR
    Commented Oct 14, 2015 at 4:54
  • @SSR That looks like it is being caused by a different part of the code that wasn't posted here. There might be an attempt to reference named createExpense() that is having a similar problem to getExpense()
    – martin
    Commented Oct 14, 2015 at 4:59
  • may i know ur mail id i will drop a mail to you .Please
    – SSR
    Commented Oct 14, 2015 at 5:01
  • @SSR I'm sorry, but I don't give that out. If you are still having trouble, you could edit this question or ask a new one.
    – martin
    Commented Oct 14, 2015 at 5:05
0

I also get this error too, I figure out I forget to add controller attribute for the component.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .