You need to sign in to do that
Don't have an account?
Gautam_Kasukhela
Scheduled Apex Batch Job Issue
Hello All,
I have an Apex class (SendEmailCommunications) that implements "Database.Batchable<sObject>,Schedulable" and has the 'start', 'execute' & 'finish' methods.
What am I missing here?
I have an Apex class (SendEmailCommunications) that implements "Database.Batchable<sObject>,Schedulable" and has the 'start', 'execute' & 'finish' methods.
global Database.QueryLocator start(Database.BatchableContext bc) { return Database.getQueryLocator( <My Query>); } global void execute(Database.BatchableContext bc, List<My_Custom_Object> scope){ System.debug('Scope Size is: '+scope.size()); //more logic } global void finish(Database.BatchableContext bc) { System.debug('Sent emails'); }I have used the 'Apex Scheduler' in Setup to schedule this class to run at a designated time. As per the logs, the batch job starts and finshes without running any logic. Even the first system.debug statement in my execute method does not get logged.
What am I missing here?
All Answers
Greetings to you!
Make sure the start method fetches the required records to process in execute method. Execute will not be called unless at least one non-null item is available for processing.
Also, please refer to the below links which might help you further.
https://salesforce.stackexchange.com/questions/112821/batch-apex-execute-method-not-invoked
https://salesforce.stackexchange.com/questions/98874/execute-method-in-apex-batch-never-called
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_batch_interface.htm#!
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas