System.UnexpectedException: No more than one executeBatch can be called from within a testmethod. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.

System.UnexpectedException: No more than one executeBatch can be called from within a testmethod. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.

If you face “System.UnexpectedException: No more than one executeBatch can be called from within a testmethod. Please make sure the iterable returned from your start method matches the batch size, resulting in one executeBatch invocation.” issue, make sure execute method inside the batch is not called more than once.

Example:

I have a controller, where I am calling a batch class where the batch size is 4. If I have created 8 records in the test class, it will fail since the execute method will be called twice.

So, make sure the execute method is called only once.

Note:

1. Make sure seeAllData=true is not used in test class since it fetches all the data from the object.

2. Check the batch size and records created in test class.

Leave a Reply