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
sancasanca 

action.setcallback function not getting called automatically

Hi Devs,

To achieve a certain functionality , I have called a server side apex controller class which inturns calls batch class .  I have written a code to hide spinner class inside action,setcallback funtion .  This never gets executed untill I manually perform a button click anywhere on the screen or switch tabs / brower window . 
Because of this ,the spinner keeps spinning and never goes off the screen until I manually click anywhere in window or switch tabs,after which the action.setcallback funtion get called (Verified in console tab)  . 
Is this happening because of batch class . How can I overcome this ?
 
Saurabh TrailheadSaurabh Trailhead
I also had this issue. In my case action.setcallback was waiting for http response, but it goes into infinite waiting until i press some button or click mouse buttons.
So here is how i solve my issue.
I used $A.getCallback method with window.Timeout wrapping $A.getCallback.

Add below code in your method.

window.setTimeout(
            $A.getCallback(function() {
                if(flag==true)
                    cmp.set("v.Spinner",false);
                else
                {
                    cmp.set("v.Spinner",false);
                    cmp.set("v.Spinner",true);
                }                        
            }), 1000
        );

Means after everysecond getCallback method will be called and if flag is true, spinner will be set to false, otherwise we just change the state of spinner and change back again. so that the component stay in scope.
flag here is boolean, and I am setting it to true when $A.setCallback function called.

Please flag this answer as best, if you are able to resolve this issue.