function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Robert Davis 42Robert Davis 42 

Invalid Constructor Name: System.debug

I have a Batch class that I am trying to debug and everytime I place a line of
System.Debug('Last Run Date'+LRDate);
or
System.Debug('query'+ qry);
I get the following errors:
Invalid constructor name: System.debug

Please help me with what I a missing. Never run into this problem before.
Robert
Best Answer chosen by Robert Davis 42
Ajay K DubediAjay K Dubedi
Hi Robert,
You cannot add a "system.debug" directly inside a class, it should be present inside a method.
If you want to debug the query then add debug inside Batch's start method.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi

All Answers

NagendraNagendra (Salesforce Developers) 
Hi Robert,

Sorry for this issue you are facing.

May I request you please post the complete code snippet of what you have so far so that we can look into it and can help you troubleshoot the issue.

Happy to help further.

Regards,
Nagendra
Robert Davis 42Robert Davis 42
Nagendra,

Thanks for the help. Below is the start of the batch class:
global class AccountABCMktgBatch implements Database.Batchable<sObject>, Database.Stateful{

	global Integer recordsProcessed = 0;
    global final String query;
    Last_Run_ABC_Mktg_Batch__c customSetting = Last_Run_ABC_Mktg_Batch__c.getInstance('PROD');
    //String LRDate = customSetting.LastRun_Date__c.formatGmt('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'') ;
    DateTime LRDate = customSetting.LastRun_Date__c;
    
    String qry = ' SELECT id, Exempt_Mktg_ABC_Partner_Num__c, Exempt_Mktg_ABC_Region__c, '
            + 'Exempt_Mktg_ABC_Region_and_Partner_Num__c, No_of_Active_Partner_Num__c '
            + ' FROM Account '
            + ' WHERE LastModifiedDate > :LRDate';
    System.debug('query'+ qry);
    global Database.QueryLocator start(Database.BatchableContext BC){
    return Database.getQueryLocator(qry);
    }
    
    global void execute(Database.BatchableContext BC, List<account> acts){
        Set<Id> accountsToUncheck = new Set<Id>();
        Set<Id> accountsToCheck = new Set<Id>();
        List<Contact> cntsToUncheck = new List<Contact>();
        List<Contact> cntsToCheck = new List<Contact>();
        if(acts.size() > 0){
            for(Account acct: acts){
                
                if(acct.Exempt_Mktg_ABC_Partner_Num__c +  
                   acct.Exempt_Mktg_ABC_Region_and_Partner_Num__c == acct.No_of_Active_Partner_Num__c){
                       accountsToUncheck.add(acct.id);
                } else if (acct.Exempt_Mktg_ABC_Partner_Num__c + 
                           acct.Exempt_Mktg_ABC_Region_and_Partner_Num__c <> acct.No_of_Active_Partner_Num__c){
                               accountsToCheck.add(acct.id);
                           }    
            }
            
        }//End Ifs (acts.size()>0)
        if(accountsToUncheck.size() > 0){
            for(Contact cnts1 : [SELECT id, ABC_Mktg__c, No_Longer_Employed__c, Email,
                                 HasOptedOutOfEmail FROM CONTACT WHERE AccountId IN: accountsToUncheck]){
                                     if(cnts1.ABC_Mktg__c = TRUE && cnts1.id !=null){
                                         Contact cont = new Contact();
                                         cont.id = cnts1.id;
                                         cont.ABC_Mktg__c = false;
                                         cntsToUncheck.add(cont);
                                     }
                                 }
        }
        if(accountsToCheck.size()> 0){
            for(Contact cnts2 : [SELECT id, ABC_Mktg__c, No_Longer_Employed__c, Email,
                                 HasOptedOutOfEmail FROM CONTACT WHERE AccountId IN: accountsToCheck]){
                                     if(cnts2.ABC_Mktg__c = FALSE && cnts2.id != null){
                                         Contact cont2 = new Contact();
                                         cont2.id = cnts2.id;
                                         cont2.ABC_Mktg__c = TRUE;
                                         cntsToCheck.add(cont2);
                                     }
                                 }
        }
        if(cntsToUncheck.size() >0){
            update cntsToUncheck;
        }
        if(cntsToCheck.size() > 0){
            update cntsToCheck;
        }
            
    
    }
    global void finish(Database.BatchableContext BC){
        
    }
		
}

I get the following PROBLEMS in the lower section of the Developer Console:

AccountABCMktg - 13 - Expecting ')' but was: 'query'
AccountABCMktg - 13 - Unexpected token ')'.
AccountABCMktg - 13 - Invalid constructor name: System.debug


Thanks again,

Robert
Ajay K DubediAjay K Dubedi
Hi Robert,
You cannot add a "system.debug" directly inside a class, it should be present inside a method.
If you want to debug the query then add debug inside Batch's start method.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
This was selected as the best answer
Robert Davis 42Robert Davis 42
Ajay,

Thank you, I never knew that. I feel a little foolish and a lot smarter.

It is the simple things.

Robert