0

I'm trying to call a function every 10 seconds. But I'm getting this error: Uncaught Error in $A.getCallback() [Cannot read property 'setCallback' of undefined]. What is wrong?

doGet : function(component, event, helper) {
    let that = this;
    let getTools = component.get("c.getTools");

    getTools.setCallback(this, function(response) {
        let state = response.getState();
        if (state === "SUCCESS") {
            component.set("v.toolObjects", response.getReturnValue());
        }
    });           
    $A.enqueueAction(getTools);

    window.setTimeout(
        $A.getCallback(function() {
            console.log('Calling');
            that.doGet(component);
        }), 10000
    );
},
0

you are calling the wrong variable in your setCallback

let that = this;
let getToolsAction = component.get("c.getTools");

getToolsAction.setCallback(this, function(response) {...
$A.enqueueAction(getToolsAction);
  • Sorry. Yes. Changed. But the error is the same. – MichaelLev19 Jul 12 at 7:28
0

Looks like you have written doGet method in controller.js instead of helper.js.

 window.setTimeout(
        $A.getCallback(function() {
            console.log('Calling');
            that.doGet(component);
        }), 10000
    );

In above code that.doGet(component); will always throw error as that will always undefined in controller.js.

Try Change Code like below should resolve your problem.

Controller.js

doGet : function(component, event, helper) {
        helper.doGet(component, event);
    }

helper.js

doGet:function(component,event) {
        let that = this;
        let getAccounts = component.get("c.getAccounts");

        getAccounts.setCallback(this, function(response) {
            let state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.toolObjects", response.getReturnValue());
            }
        });           
        $A.enqueueAction(getAccounts);

        window.setTimeout(
            $A.getCallback(function() {
                console.log('Calling');
                that.doGet(component);
            }), 100
        );
    },
  • No. It's actually in helper :) I call it in controller in doInit. – MichaelLev19 Jul 12 at 11:43
  • Actually you have added helper in function parameter so thought you have created in controller. Can you please add log after line let getTools = component.get("c.getTools"); to get getTools has value or not? – Dhanik Lal Sahni Jul 12 at 13:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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