0

Ive been working on this class to update a field on a related record with a field (zone) on the account record. When I try to test using "Id batchJobId = Database.executeBatch(new UpdateMarketPlaceFieldBatchV2(),200);" I get an error message "Line: 1, Column: 39 Constructor not defined: [UpdatezoeFieldBatchV2].()" What am I missing that is causing the error?

global class UpdatezoneFieldBatchV2 implements Database.Batchable<SObject>{
global String qry;
global integer recordsProcessed = 0;

global UpdatezoneFieldBatchV2(String q, String e){
    qry=q;
}

global Database.qryLocator start(Database.BatchableContext BC){
    qry = 'Select Id, zone__c From Vehicle__c where Account__c != null';
    return Database.getqryLocator(qry);
}

global void execute(Database.BatchableContext BC, List<Vehicle__c> scope){
    List<Vehicle__c> veh = [Select Id, zone__c From Vehicle__c where Account__c != null];
    Map<Id, Account> accts = new Map<id, Account>([SELECT zone__c FROM Account WHERE Id IN (SELECT Account__c FROM Vehicle__c WHERE Id = :scope)]);
    for(Vehicle__c e : veh){
        Account a = accts.get(e.Account__c);
        e.zone__c = a.zone__c;
        recordsProcessed = recordsProcessed  + 1;
    }
    update veh;
}

global void finish(Database.BatchableContext BC) {
    System.debug(recordsProcessed + ' records processed');        
}
}

1 Answer 1

4

The error message is literally accurate. You cannot instantiate your batch class via

Id batchJobId = Database.executeBatch(new UpdateMarketPlaceFieldBatchV2(),200);

because your batch class does not have a no-argument constructor, which the error represents as [UpdatezoeFieldBatchV2].(). Your constructor takes two required arguments, although it doesn't do anything at all with one of them:

global UpdatezoneFieldBatchV2(String q, String e){
    qry=q;
}

You must provide both when you instantiate the class.


As a side note, unless you are building a managed package and wish to expose this class to outside callers, you should not declare this class or any of its members global.

You must log in to answer this question.

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