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
Imtiyaz Ali 16Imtiyaz Ali 16 

Hello, when i run apex batch class or Scheduler class then it will count against the salesforce daily api limit or not? Any help would be appreciated.

I am using apex scheduler class and apex batch class, I want to know that when i run apex batch class or Scheduler class then it will count against the salesforce daily api limit or not? Any help would be appreciated.
Thanks in advance.
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi lmtiyaz,

You may attempt to use the following code sample to avoid encountering this limit, particularly if the batch is executed in a scheduled class.
  • Count how many current jobs are being executed.
  • This information is stored in the AsyncApexJob table.
  • Before calling the Database.executebatch() method within a scheduled class, you should try something like:
  • check if there are 5 active batch jobs
  • In some cases, might need to add "Status='Queued' " to the criteria
if ([SELECT count() FROM AsyncApexJob WHERE JobType='BatchApex' AND (Status = 'Processing' OR Status = 'Preparing')] < 5){ 
   Database.executeBatch(batchClassInstance);
} else {
   //schedule this same schedulable class again in 30 mins
   nameOfYourSchedulableClass sc = new nameOfYourSchedulableClass();
   Datetime dt = Datetime.now().addMinutes(30);  // i.e. 30 mins
   String timeForScheduler = dt.format('s m H d M \'?\' yyyy');
   Id schedId = System.Schedule('MatrixRetry'+timeForScheduler,timeForScheduler,sc);
}
  • In the same 'else' clause you can send an e-mail to yourselves so you're notified that the job will run a bit later than normal.

Note: You can have more than 5 scheduled classes that will call Database.executeBatch() in a Queued status

Please mark it as best answer if the information is informative.

BestRegards
RahulKumar
Imtiyaz Ali 16Imtiyaz Ali 16
Hi RahulKumar!
Thanks for your quick reply.
Let me check your given steps, but I want to know , is there any document from salesforce where this is mention that execut() of scheduler class and apex batch class count against "salesforce daily api limit".
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Imtiyaz,

May I request you to please check salesforce help document provided below. I hope it will be helpful.

Please mark it as best Answer if the information is informative.

BestRegards
RahulKumar