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 use constructor with two parameters in batch apex and how to write test class for the same?

While covering the below batch apex im getting a error 'System.UnexpectedException: Start did not return a valid iterable object.'

I exected the batch class like:
batchClass b = new batchClass(idSet, stringMap);
Database.executeBatch(b,1);

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

        Set<Id> idSet = new Set<Id>();
        Map<String, String> stringMap = new Map<String, String>();
        
        public batchClass(Set<Id> idSet, Map<String, String> stringMap){
            this.idSet = idSet ;
            this.stringMap = stringMap;
        }
        
        global Database.QueryLocator start(Database.BatchableContext BC){         
                String query = 'Query';
                return Database.getQueryLocator(query);
            }

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

 
JayantJayant
What you pasted looks good, seems the actual code has issues. Can you paste the actual code rather than pseudo code ?