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
Shanmuga Prasath PushpanathanShanmuga Prasath Pushpanathan 

how to write a scheduler apex for the batch apex which has parameter?

When I tried to schedule batch apex, I got error saying that Contructor is not defined so i have created the scheduler apex 

Batch apex :
global class batchclass implements Database.Batchable<sObject>{

    Set<Id> accountIdSet = new Set<Id>();

    global batchclass(Set<Id> accountIdSet){
        if(accountIdSet != null){
            this.accountIdSet= accountIdSet;
        }
    }

    global Database.QueryLocator start(Database.BatchableContext BC){
        
        return Database.getQueryLocator('SELECT Id, Region__c,'+
                                     'FROM Account '+
                                     'Where Id IN: accountIdSet');
        
    }

    global void execute(Database.BatchableContext BC, List<SObject> scope) {
        //logic
    }

    global void finish(Database.BatchableContext BC) {
        //doing nothing
    }

}

Sheduler apex : 
global class Schedulerapex implements Schedulable {
    
   Set<Id> accntSet = new Set<Id>();
    
   //constructor
    global batchclass(Set<Id> accountIdSet){
        
        accntSet = accountIdSet;
        
    } 
    
   global void execute(SchedulableContext sc) {
      batchclass updateAccountBatch = new batchclass(accntSet); 
      database.executebatch(updateAccountBatch, 1000);
   }
}

In this scheduler apex how to pass the accountIdSet?
Do we need to query the account in the scheduler apex for passing the parameter to batch class?