22

I am getting "AsyncApexExecutions Limit Exception" in below code -

Can anyone explain the issue? i have been getting more than 1 lakh records in start method using queryLocator but didn't get this exception. So what is wrong in this code

global class SyncCalendarsUpdates implements Database.Batchable<sObject>, Database.AllowsCallouts {
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id, Event_ID__c, Description__c, Event_Owner__r.Id, Subject__c, Start_Datetime__c, End_Datetime__c, Click_Key__c FROM Updated_Event__c';
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Updated_Event__c> scope) {

    }

    global void finish(Database.BatchableContext BC) { }
}
4
  • What sort of triggers do you have on Event and Updated_Event__c?
    – Adrian Larson
    Commented Jan 20, 2015 at 17:20
  • I am getting this exception if i comment entire code of Execute method also so i don't think trigger is playing any role in it Commented Jan 20, 2015 at 17:33
  • I see you have a callout in execute() -- there is a V32 limit of 100 per execute() -- how big is scope? - By the way, you should do the callout if running testmethods and mock the response - otherwise it will be hard to assert / get code coverage
    – cropredy
    Commented Jan 20, 2015 at 23:49
  • I have modified the code to avoid doubts. Still i am getting this exception Commented Jan 21, 2015 at 5:33

4 Answers 4

22

'AsyncApexExecutions Limit Exception' means you are hitting an org wide 24 hour rolling limit on asynchronous Apex.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_limits.htm "The maximum number of asynchronous Apex method executions (batch Apex, future methods, Queueable Apex, and scheduled Apex) per a 24-hour period: 250,000 or the number of user licenses in your organization multiplied by 200, whichever is greater"

Adding the result of these two queries should help you see where you are at:

Integer nonBatchAsyncApexJobs = [SELECT count() FROM AsyncApexJob WHERE JobType != 'BatchApexWorker' AND JobType != 'BatchApex' AND CreatedDate >= :DateTime.now().addDays(-1)];

AggregateResult[] ar = [SELECT SUM(JobItemsProcessed) FROM AsyncApexJob WHERE JobType = 'BatchApex' AND CreatedDate >= :DateTime.now().addDays(-1)];

Integer batchJobItemsProcessed = Integer.valueOf(ar[0].get('expr0'));

Integer total = nonBatchAsyncApexJobs + batchJobItemsProcessed;

System.debug('total: ' + total);

The second query can be especially important because JobItemsProcessed represents the number of batches processed in a BatchApex type AsyncApexJob. Each batch is counted towards the limit and this can add up quickly depending on the run frequency and records processed per batch.

2
13

You can now (as of Spring 19) check the applicable org wide limit directly from Apex:

Map<String,System.OrgLimit> limitsMap = OrgLimits.getMap();
System.OrgLimit asyncLimit = limitsMap.get('DailyAsyncApexExecutions');
System.debug('Usage Value: ' + asyncLimit.getValue() + '/' + asyncLimit.getLimit());

07:31:06:068 USER_DEBUG [6]|DEBUG|Usage Value: 250004/250000

This is the same data that is exposed via the REST Limits resource.

12

I realize this is an old thread. Putting this here to help others who run into this.

You can use SFDX to check org limits with the following command

sfdx force:limits:api:display -u <username or alias>
1
  • I just now had a need to do this, and found your post. This is awesome, thanks for posting this! Commented Jul 26, 2019 at 17:03
5

Many, many limits can be found by querying /services/data/v46.0/limits within Workbench's REST Explorer: screenshot of Workbench's Rest Explorer with DailyAsyncApexExecutions expanded

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .