0
global class AccountkeepingBatch implements Database.Batchable<Sobject>, Database.stateful {

    global String query;
    global Keeping__c pkRecord;
    global Integer numRecords;

    global AccountkeepingBatch(Keeping__c pk) {
        this.pkRecord = pk;
        System.debug('pk -->' + pk);
        this.numRecords = 0;
    }

    global Database.QueryLocator start(Database.BatchableContext bc) {

        Id BusinessAccount = getRecordTypeIdByDeveloperName(Utils.BUSINESSACCOUNT_READONLY_RT);
        Id PersonAccount = getRecordTypeIdByDeveloperName(Utils.PERSONACCOUNT_READONLY_RT);
        return Database.getQueryLocator('SELECT Id,IsPersonAccount,RecordTypeId FROM Account WHERE LastModifiedDate < ' + pkRecord.Job_Start_Date_Time__c.formatGmt('yyyy-MM-dd\'T\'HH:mm:ss\'Z\'') +
                'AND RecordTypeID IN (\'' + BusinessAccount + '\', \'' + PersonAccount + '\')');
    }

    global void execute(Database.BatchableContext bc, List<Account> scope) {
        this.numRecords += scope.size();
        System.debug('scope -->' + scope);

        Id deactivatedBusinessAccount = getRecordTypeIdByDeveloperName(Utils.BUSINESSACCOUNT_DEACTIVATED_RT);
        Id deactivatedPersonAccount = getRecordTypeIdByDeveloperName(Utils.PERSONACCOUNT_DEACTIVATED_RT);

        System.debug('deactivatedBusinessAccount RT ->' + deactivatedBusinessAccount);
        System.debug('deactivatedPersonAccount RT ->' + deactivatedPersonAccount);

        DateTime deactivationTime = System.now();
        for (Account acc : scope) {
            System.debug('acc -->' + acc);
            acc.IsDeactivated__c = true;
            acc.DeactivatedDateTime__c = deactivationTime;
            if (acc.IsPersonAccount) {
                acc.RecordTypeId = deactivatedPersonAccount;
            } else {
                acc.RecordTypeId = deactivatedBusinessAccount;
            }
        }
        update scope;
    }

    global void finish(Database.BatchableContext bc) {

    }

    private Id getRecordTypeIdByDeveloperName(String name){
        return Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get(name).getRecordTypeId();
    }
}

I try to run the batch class in the execute anonymous window

Database.executeBatch(new AccountkeepingBatch(Keeping__c pk),200);

I get the error as

Line: 1, Column: 22 Unexpected token '('.

Could you please tell me what I did wrong here?

1 Answer 1

1

You need to pass an instance of Keeping__c into the constructor:

Keeping__c pk = new Keeping__c(...);
Database.executeBatch(new AccountkeepingBatch(pk), 200);

The argument type (Keeping__c here) is not supplied when invoking a method or constructor.

1
  • Thank you. Now, I see the mistake Jun 6, 2019 at 15:28

You must log in to answer this question.

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