0

I'm debugging a batch class which auto creates a transaction record (a custom SObject).

The following is my executeBatchMethod() ,

@InvocableMethod(label='desc.' description='desc.')
 public static void executeBatchMethod() {
    if(Test.isRunningTest() || Date.Today().day()==Integer.valueOf(Label.TEST_ONE)) {
        System.debug('----execute method called'); //This debug shows up on the logs
        Database.executeBatch(new TEST_AutoCreateTransaction(1), 400);
    }    
}

This method is expected to trigger the start(Database.BatchableContext bc) method, but this is currently not happening. Following is the start method,

global Database.QueryLocator start(Database.BatchableContext bc) {
    try {             
        System.debug('----start method called'); //This debug does not show up on the logs
        String query = 'select id, TEST_Amount__c from TEST_relatedTransaction__c';
        return Database.getQueryLocator(query);
    } catch (Exception ex){
        System.debug('e.getMessage(): ' + ex.getMessage());
        return null;
    }             
}

I've verified that the query returns results and the general data setup required for the batch to run is in place. I'm trying to understand why the start(...) method does not run.

11
  • 1
    How are you calling executeBatchMethod from your test, and have you applied Test.startTest and Test.stopTest around that invocation? Async processing is only processed when added after Test.startTest and is actually processed synchronously on Test.stopTest.
    – Phil W
    Commented Mar 1, 2022 at 17:03
  • I'm not calling it from a test class. I'm running them via a flow. I run (debug) the flow manually every time I want the batch to run.
    – Kishan B
    Commented Mar 1, 2022 at 17:13
  • Is an exception occurring (e.g. because Label.TEST_ONE cannot be converted to an integer, or some exception from the constructor of your batch) that stops the Database.executeBatch from being correctly executed? BTW, the use of a label in this way is an anti-pattern. You should use custom metadata or custom settings for configuration.
    – Phil W
    Commented Mar 1, 2022 at 17:16
  • 1
    OK. Well, for me there isn't enough info in the question to help further. So unless someone else has any ideas I can only wish you the best of luck in working it out! (I think the issue must be outside the code shared here, if the unit test functions correctly.)
    – Phil W
    Commented Mar 1, 2022 at 17:33
  • 1
    @PhilW, Ive figured out the issue. It was a rogue if block inside the block which was not running. So the execution just went through without exceptions but was not producing the results. Once its fixed, the batch runs without an issue. Im closing this question. Thank you for your help.
    – Kishan B
    Commented Mar 3, 2022 at 12:05

1 Answer 1

0

The issue occurred due to a logic issue in the code. There were no errors on the code in question or the execution.

You must log in to answer this question.

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