I should see this debug: "Batch starts" but this debug does not exist. Variables didn't change too. What should I do so that I could see debugs and modify variables in the execute method? I have this code to run batch:

Database.executeBatch(new PatchPanelTriggerClassTestBatch());

And this is code for batch:

global with sharing class PatchPanelTriggerClassTestBatch implements Database.batchable<SObject> {

    private static Boolean flagForTest = false;

    public static Integer toRemove = 0;

    global void execute(Database.BatchableContext param1, List<Patch_Panel__c> param2) {
        System.debug('Batch starts');
        flagForTest = true;

        for (Patch_Panel__c p : param2) {
            List<Interface__c> records = [SELECT Name, Id, Status__c, Port_No__c, Rack__c, Show_in_Customer_Portal__c FROM Interface__c where Name LIKE :p.Name];
            if (thereIsNoDuplicates(records) == false) {
                flagForTest = false;

        System.debug('Batch ends');

    static Boolean thereIsNoDuplicates(List<Interface__c> records) {
        // body of method

    global void finish(Database.BatchableContext param1) {

    global Database.QueryLocator start(Database.BatchableContext param1) {
        String s = 'select Name, Total_No_of_Ports__c from Patch_Panel__c';

        return Database.getQueryLocator(s);
  • Can you check if records are there ? Also check in Apex Jobs the number of Batches formed Jun 15, 2020 at 10:19
  • Batch is executed (I checked it by creating constructor) but debugs in methods (start, execute, finish) aren't shown and variables aren't changed.
    – NickName43
    Jun 15, 2020 at 10:45
  • 1
    if your debug level is set to APEX INFO, WARN, or ERROR, the system.debug will not appear
    – cropredy
    Jun 16, 2020 at 4:58

1 Answer 1


You don't have debug statements in your start or finish methods, so you won't see anything if the query does not return any records.

The start method is when your batch process actually starts to run and the platform starts gathering the records to process. If its query returns an empty list then the execute method is not run (and you won't see the debug statement in your logs).

You might want to remove that SOQL query from within your loop too, for performance and best practice reasons.

  • I added debugs in start and finish methods and I checked SOQL query - it returns 12 093 records - so it's valid. But debugs still aren't visible and variables don't change values.
    – NickName43
    Jun 15, 2020 at 14:10

You must log in to answer this question.

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