You need to sign in to do that
Don't have an account?
AsyncApexExecutions Limit exceeded error for my batch apex on custom object.
I wrote a batch apex that selects all the records from updated events object. When ever this batch apex is scheduled it throwing the forrlowing error:
AsyncApexExecutions Limit exceeded.
Following is my batch apex 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) {
Map<String, String> clickKeyMap = new Map<String, String>();
for (Updated_Event__c e : scope) {
Boolean doUpdate = true;
if (e.Subject__c != null) {
if (e.Subject__c.left(2) == 'SV' && e.Click_Key__c != null && e.Click_Key__c != '') {
doUpdate = false;
}
}
if (doUpdate) {
ClickCalendar cal = new ClickCalendar(e.Event_Owner__r.Id, e.Start_Datetime__c, e.End_Datetime__c, e.Subject__c, e.Click_Key__c);
cal.buildUpdateRequest();
if (!Test.isRunningTest()) {
HttpResponse resp = cal.getResponse();
if (e.Click_Key__c == null) {
String key = cal.getKeyFromResponse(resp);
if (e.Event_ID__c != null) {
clickKeyMap.put(e.Event_ID__c, key);
}
}
}
}
e.Is_Synced__c = true;
}
update scope;
List<Event> eventsToUpdate = [SELECT Id, Click_Key__c FROM Event WHERE Id IN :clickKeyMap.keySet()];
for (Event e : eventsToUpdate) {
e.Click_Key__c = clickKeyMap.get(e.Id);
}
update eventsToUpdate;
}
global void finish(Database.BatchableContext BC) { }
}
We have 1,500,000 records in that object.
update eventsToUpdate;
This is a DML Statement, which has a governing limit of 10,000.You are updating your batch at the end, and not on each iteration.
Put "LIMIT 9999" on the end of your query. If this works then this is your issue.
Your solution would be to do a database.executebatch(b, 1) which adds or breaks apart the records into 9999 records or less at a time to a list then updates that list.
All Answers
Hi Vishnu,
It looks like your hitting governing limits. Try to have them processed 1 by 1.
Also, to activate this, add that class to your apex scheduled jobs or run this command in the DEBUG Console Execute code window (This will run it at 4am daily)
System.schedule('myScheduler', '0 0 4 * * ?', new SyncCalendarsUpdates_Schedule());
It still throws me the same error.
update eventsToUpdate;
This is a DML Statement, which has a governing limit of 10,000.You are updating your batch at the end, and not on each iteration.
Put "LIMIT 9999" on the end of your query. If this works then this is your issue.
Your solution would be to do a database.executebatch(b, 1) which adds or breaks apart the records into 9999 records or less at a time to a list then updates that list.
Solution: Increase the batch size from Database.executeBatch(batchClass, 1) to Database.executeBatch(batchClass, 200)