0

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?

3
  • 1
    What is the size of the scope you are getting in Start method? Commented Dec 23, 2016 at 13:59
  • 3
    You get separate logs for your execute blocks. You should go to Setup > Monitor > Jobs > Apex Jobs and look at your batch executions. You should see columns for Total Batches and Batches Processed. If those are both zero, then you know for sure your batch is not executing.
    – Adrian Larson
    Commented Dec 23, 2016 at 14:11
  • 3
    You can run the query 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.
    – Keith C
    Commented Dec 23, 2016 at 16:59

1 Answer 1

2

If the start and finish method is getting executed and execute method is getting executed, then for sure the query in your start method is not returning anything. Please make sure you have the custom object records in your system where CreatePersonAccount__c = true. I don't see any problem in your batch class.

You must log in to answer this question.

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