I have a batchable class that is supposed to query a set of records and then create person account records based on the information in some of the fields. In the finish section it sends an email. The Start method and the Finish method execute, but the execute method does not, placing a debug statement in the first line of execute never writes to the debug log.
I followed the only detailed example I could find in the documentation, but can't see where I went wrong. As I understand it the query locator in start should pass a record set to execute that I can then manipulate, but it never enters the execute code.
global class CreatePersonFromCaseContactBatchable implements Database.Batchable<sObject>{
String resultMessage = 'Create Person From Case Contact Batch ran at: ' + datetime.now() + '\n';
String subjectLine = 'CreatePersonFromCaseContactBatchable Has Run';
global Database.QueryLocator start(Database.BatchableContext BC){
System.debug('in start');
String query = 'SELECT Id, FirstName__c, LastName__c, EmailAddress__c, CreatePersonAccount__c FROM aCustomObject__c WHERE CreatePersonAccount__c = true';
System.debug('query result '+Database.getQueryLocator(query));
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<aCustomObject__c> scope){
List<Account> aList = new List<Account>();
Id personRecordType = StaticUtilities.personRecordType;
System.debug(scope);
System.debug('in execute');
// execute logic
}
global void finish(Database.BatchableContext BC){
resultMessage += 'in finish';
System.debug('All Done');
// send email
}
}
So the debug statements in execute never write, although those in start and finish do, the email sends as well. Am I mistaken that Start should be passing records to execute in the fashion I did it? Or is there some other issue?
Setup
>Monitor
>Jobs
>Apex Jobs
and look at your batch executions. You should see columns forTotal Batches
andBatches Processed
. If those are both zero, then you know for sure your batch is not executing.SELECT Id, FirstName__c, LastName__c, EmailAddress__c, CreatePersonAccount__c FROM aCustomObject__c WHERE CreatePersonAccount__c = true
in the Developer Console to verify that there are records returned.