+1 vote
144 views
by (163k points)

I am trying to write a test method for my batch class so I can deploy it, but I am getting this error.

System.UnexpectedException: Start did not return a valid iterable object.

The batch class looks like this:

public class DataLoadBatch implements Database.Batchable<SObject>, Database.Stateful,  Database.AllowsCallouts{

    public static AppCustomSettings__c AppCustomSettings= AppCustomSettings__c .getInstance('API Integration');

    public List<Contact> start(Database.BatchableContext bc) {
        List<Contact> contacts = ExternalAPI.getContactIdsToLoad(AppCustomSettings.API_Key__c);
        return contacts;
    }

    public void execute(Database.BatchableContext bc, List<Contact> scope) {
        try {
            update scope;
        }catch (DmlException e) {
            System.debug('DML Error---------> ' + e.getMessage());
        }
    }

    public void finish(Database.BatchableContext BC) {
    }


}

The test class looks like this so far:

@IsTest
static void testContactIDLoad() {
   AppCustomSettings__c AppCustomSettings= new AppCustomSettings__c();
   AppCustomSettings = 'API Integration';
   AppCustomSettings.Base_URL__c = 'https://example.com/api/v1';
   AppCustomSettings.API_Key__c = '12345678xxxxxapikey';
   insert AppCustomSettings;

   Test.setMock(HttpCalloutMock.class, new ContactHTTPResponseMock());

   Test.startTest();
    ContactLoadBatch clBatch = new ContactLoadBatch();
    Database.executeBatch(clBatch);
   Test.stopTest();
}

To resolve, I tried to create a list of contact records and pass that into the database.execute() method as as the 2nd parameter, but I then got an error indicating "method does not exist or incorrect signature: void executeBatch(ContactLoadBatch,List) from the type Database"

How can I resolve this error?

1 Answer

Welcome to Memory Exceeded, where you can ask questions and receive answers from other members of the community.
...