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
EldonEldon 

Repeated server calls in Lightning

Hi,

I need to call an apex server function in lightning in every 10 seconds.Is there anyway to achieve this?

Thank you
Aabhi BattaAabhi Batta
hello,
there is a way to call function every 10 second's ​ but its not good practice
({
	doInit : function(component) {
        function fun(){
            alert('2');
            //Call APex server here ex()
          var call=component.get("c.echo");
          setInterval(function(){ fun(); }, 10000);

        }
        alert('1');
        fun();
	}
})

 
Ajay Sharma SFAjay Sharma SF
@Eldon : Aabhi Batta is right. You call your apex method from doInit or afterScriptLoaded you have to use setInterval with 10000 miliaseconds(10 sec). It is not a good practice however. Your apex calls should always be event based.