We are trying to create an Apex batch job, but the start() method never seems to be called. The class we are using for the job has the following code:
global class BatchableScorer implements Database.Batchable<sObject>, Database.Stateful {
global List<Contact> passedContacts;
global BatchableScorer(List<Contact> passedContacts) {
System.debug('Constructor called');
System.debug(passedContacts);
this.passedContacts = passedContacts;
}
public Database.QueryLocator start(Database.BatchableContext bc) {
System.debug('start() called');
return Database.getQueryLocator([SELECT Id, FirstName FROM Contact]);
}
global void execute(Database.BatchableContext bc, List<sObject> scope){
System.debug('execute() called');
for (sObject c : scope) {
System.debug(c);
}
}
global void finish(Database.BatchableContext bc){
System.debug('finish() called');
AsyncApexJob job = [SELECT Id, Status, NumberOfErrors,
JobItemsProcessed,
TotalJobItems, CreatedBy.Email
FROM AsyncApexJob
WHERE Id = :bc.getJobId()];
}
}
The code we are using to start up the job is:
BatchableScorer bct = new BatchableScorer(passedContacts);
ID batchprocessid = Database.executeBatch(bct);
List<AsyncApexJob> myrunningjob = [Select Id, Status, ApexClass.Name From AsyncApexJob where Id=:batchprocessid];
System.debug(myrunningjob);
When we add the job via executeBatch, we see the constructor gets called and the debug output shows that we create a job, with an ID, with a state of 'Holding'.
When we check the Apex Jobs page there is nothing in the list, and the start() method never gets called (we don't see any debug message).
Can anyone suggest what might be going on here? Are we missing something?
EDIT: In response to questions / comments by Ajay, I just want to be clear: right now, the code executes correctly in the context of 'Execute Anonymous'. However it does not run from the VFP controller, even though it's the same code and we do see the constructor called correctly (start is not being called when in the context of the controller).
List<Contact> passedContacts
is empty?passedContacts
should be private