4

I execute the following in the anonymous execution:

Database.executeBatch(new TransferACDCAccountOppOwnerBatch(), 200);

The class is below. It uses Batchable interface. I put in a bunch of debug statements but don't see anything in the logs in the console. I also create debug logs at Debug level for Apex, etc. and also don't see any of the system.debug output. The SOQL itself I know works and should only return one row in the developer sandbox test data I setup.

Is there something about the batchable interface that doesn't allow system.debug output? I know it's asynchronous, but the job completes and I see plenty of log information. I just don't see any system.debug output.

global class TransferACDCAccountOppOwnerBatch implements Database.Batchable<sObject> {

    String query;

    static String type = 'Accountant';
    static String stageName = 'Closed Won';
    static String numberEmployees = '<5';

    global TransferACDCAccountOppOwnerBatch() {
        query = 'SELECT Id, Num_Active_Orgs__c, Num_Active_Paying_Orgs__c,Number_of_Bookkeeping_Clients__c, Number_Bookkeeping_Clients_SR__c,' +
                'Num_Targeted_Orgs__c, AccountId, Account_State__c, Biz_Dev_Owner__c,CloseDate, IsClosed, Name, Type, OPS_ID__c, Org_Creator__c,' +
                'Org_s_Geographical_State__c, OwnerId, StageName, Tier__c, IsWon,First_targeted_Org__r.NumberEmployees__c, Account.name, Account.owner.name' +
                ' FROM Opportunity' +
                ' WHERE StageName = :stageName' +
                ' And type = :type' +
                ' And CloseDate < Last_90_Days' +
                ' And First_targeted_Org__r.NumberEmployees__c = :numberEmployees'; 
    }

    global Database.QueryLocator start(Database.BatchableContext BC) {
        System.debug('start query');
        return Database.getQueryLocator(query);
    }

    global void execute(Database.BatchableContext BC, List<Account> scope) {
        System.debug('execute batch transfer');
        TransferACDCAccountOppOwnerHandler hierarchy_handler = new TransferACDCAccountOppOwnerHandler();
        hierarchy_handler.setup(scope, BC.getJobId());
        System.debug('after hierarchy handler setup');
        // hierarchy_handler.runMatching();
        // hierarchy_handler.processConsoles();
        // hierarchy_handler.processGlobalConsoles();
        // hierarchy_handler.commitUpdates();

    }

    global void finish(Database.BatchableContext BC) {
        System.debug('finish bath');
    }
}
Reshma
  • 326
  • 6
  • 13

4 Answers4

0

Debug logs are limited to 2MB if they go over that size salesforce unhelpfully remove debug lines in an attempt to reduce the size to below the limit.

If you have a particularly noisy class you can override the logging for that class.

Check out the documentation here: https://help.salesforce.com/articleView?id=code_setting_debug_log_levels.htm&type=0&language=en_US&release=206.20

thegogz
  • 654
  • 6
  • 14
0

A quick and easy hack that I sometimes use would be to set your debog levels to ERROR, and then every time you want to debug you just do
System.debug(LoggingLevel.ERROR, 'Debug message goes here');
Just don't forget to clear your debug lines when you're done, so as not to make the problem worse going forward.

AvailableName
  • 666
  • 4
  • 13
  • 24
  • 1
    Thanks for everyone's responses. I've tried the different tips. However, the issue remaining is that ... in the logs, I can see in the logs debug statements for the start of the batch query. I can also see a debug log output for when the batch job finishes (bdclog finish batch). However, I don't see debug log output for the "execute" of the batchable code even though I can see in the logs that the query correctly returns 10 rows from the getQueryLocator(query) call. I don't understand why the "bdclog execute batch transfer" doesn't show up in the logs. I'll paste code in next comment – Ed SFDC Developer May 11 '17 at 18:46
  • global class TransferACDCAccountOppOwnerBatch implements Database.Batchable { String query; static String type = 'Accountant'; global TransferACDCAccountOppOwnerBatch() { query = 'SELECT Id, Num_Active_Orgs__c FROM Opportunity Where Type=:type ' + ' LIMIT 10' ; } global Database.QueryLocator start(Database.BatchableContext BC) { System.debug(LoggingLevel.INFO, 'bdclog start query'); return Database.getQueryLocator(query); } – Ed SFDC Developer May 11 '17 at 18:54
  • Here's the rest of code since comments number of characters are capped: – Ed SFDC Developer May 11 '17 at 18:55
  • global void execute(Database.BatchableContext BC, List scope) { System.debug(LoggingLevel.INFO,'bdclog execute batch transfer'); } global void finish(Database.BatchableContext BC) { System.debug(LoggingLevel.INFO,'bdclog finish batch'); } } – Ed SFDC Developer May 11 '17 at 18:55
0

Turns out that in the Execute method I was passing List instead of List while the query was against Opportunity.

Also, seems like setting LoggingLevel.INFO helps at least with getting debug messages sent to developer console when running this batchable class in anonymous execution.

Thanks for the tips!

0

System.dubug is supported in batch apex. As batch apex runs asynchronously, so it creates multiple logs based on your batch size. So, look at every log file that is created when batch apex completed its execution.