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

Calling apex in every 3 seconds.

Hi Everyone.


We have a requirement in salesforce where i need to communicate with other system using API -- which is not a problem .


But the problem is the other ther system is very old and it can handle only one requests in every 3 seconds. So i cant sent multiple requests in one go.


So did any body has done anything like those before? 


I know following options, but none of them meet our requirements:


1) Using VF page and Actionpoller. But this need VF page to be open all the time & doesnt meet our requirements. we want more dynamic and reliable.


2) Introduce delay in apex code by usign dummy for loop to run for random times - This is not good way & we are more likely to hit the script statments limit . 


4) I can use the apex schduler but salesforce gives flexibility to run every hour not every min. :(  So i need to send atleast 60 requests in every hour, even this fails to meet our requirment.


3) Use Cronkit  app - As we are already use it for other functioanlity. I am not sure how best it can be used.   Can any one please answer my following basic fuction:


a) As of now we use cornkit to implement one class to execute every 15 mins . So can i create one more cron batch in the same org to execute one more class??  


b) What minimum frequency can i set up a cron batch, Can it be as low as 1 min. ?


c) present bacth with is supposed to run every 15 min runs some wherre around 25 min , so adding one more cron bacth would have any impact on the exisiting ones or the new ones?



If any one has implemented any thing of this sort of requirement, please share your thoughts.





Dhaval PanchalDhaval Panchal

Hi You can use Schedule Apex,

See below example, which is calling after every 1 min (you can change it to 3 sec).

You need to call only once, then apex will schedule next call automatically.


global class scheduledTest implements Schedulable{
    global void execute(SchedulableContext SC) {
        String day = string.valueOf(;
        String month = string.valueOf(;
        String hour = string.valueOf(;
        String minute = string.valueOf( + 1);
        String second = string.valueOf(;
        String strJobName = 'Job-' + second + '_' + minute + '_' + hour + '_' + day + '_' + month;
        String strSchedule = '0 ' + minute + ' ' + hour + ' ' + day + ' ' + month + ' ?';
        System.schedule(strJobName, strSchedule, new scheduledTest());


If there is a middleware which can connect to both ends (Salesforce and your own API endpoint), you can use it to poll the system every 3 seconds and relay the information to Salesforce via an API call.

Satish Kumar

Hi Panchal,


Your code works fine for minute but the same code doesnt work when i use it for seconds. unfortunatley..

Dhaval PanchalDhaval Panchal
You are right Nask,

I am using this code for 1 min. I tried it for second but its not working. :(