1

I am sure there is a simple explanation but when I run in Anonymous Apex my Batchable class I get error: Constructor not defined: [BatchableEncryptedEmailBackfill].<Constructor>(). It is to my understanding that I need to define the constructor with 'ApexPages.StandardController' when there is an extension class. Could someone break down the basics of a Constructor that I am missing? Why would I need a constructor with this class?

This is what I am calling in Anonymous:

BatchableEncryptedEmailBackfill a = new BatchableEncryptedEmailBackfill();
database.executebatch(a);

This is the batachable class:

global class BatchableEncryptedEmailBackfill implements 
    Database.Batchable<sObject>,Database.AllowsCallouts,Database.Stateful{

    global final String Query;
    global final String Entity;
    global final String Field;
    global final String Value;

    global BatchableEncryptedEmailBackfill(String q, String e, String f, String v){
        Query=q; Entity=e; Field=f;Value=v;
    }

    global Database.QueryLocator start(Database.BatchableContext BC){
        String query = 'SELECT Id FROM Lead WHERE pi__url__c != NULL AND Encrypted_Email_String__c = NULL';
        return Database.getQueryLocator(query);
    }  

    global void execute(Database.BatchableContext BC, List<Lead> listLead){
        List<Lead> changedLeads = new List<Lead>();
        for(Lead l: listLead) {
            if(l.Web_Id_NatFund__c != NULL) {
                String val = l.id + ',' + l.Web_Id_NatFund__c;
                ConsoleApplicationLinkController.getShortenedLinkLT(val);
            }
        }
        /* DO NOT NEED TO UPDATE LEADS- UPDATE IS HAPPENING IN GETSHORTENEDLINK METHOD*/
    }

    global void finish(Database.BatchableContext BC){
        system.debug('got into finish:' + BC);
        AsyncApexJob a = [SELECT Id, Status, NumberOfErrors, JobItemsProcessed,
                          TotalJobItems, CreatedBy.Email
                          FROM AsyncApexJob WHERE Id =
                          :BC.getJobId()];
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        String[] toAddresses = new String[] {a.CreatedBy.Email};
            mail.setToAddresses(toAddresses);
        mail.setSubject('Apex Sharing Recalculation ' + a.Status);
        mail.setPlainTextBody
            ('The batch Apex job processed ' + a.TotalJobItems +
             ' batches with '+ a.NumberOfErrors + ' failures.');
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
    }
}

1 Answer 1

3

You have only one constructor defined:

global BatchableEncryptedEmailBackfill(String q, String e, String f, String v)

Yet you are trying to call one where you pass nothing in:

new BatchableEncryptedEmailBackfill() // this constructor is not defined

It's not clear what values you want to pass for q, e, f, and v, but your actual constructor call needs to pass a value for each:

String query = 'SELECT ... FROM ... WHERE ...';
String entity = 'Contact'; // for example
String field = 'Email'; // for example
String value = 'Some Value';
Database.executeBatch(new MyBatch(query, entity, field, value));
1
  • Ah that totally makes sense. I was thinking I was calling the class and not the constructor of the class. I removed the constructor (I don't see what I need it) and was able to run the Anonymous block.
    – Olivia
    Commented Oct 5, 2017 at 21:35

You must log in to answer this question.

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