Further Testing
Interface
public interface FauxBatch extends Database.Batchable<Account> {
void initialize(Account[] data);
}
Implementation
public class FauxBatchImpl implements FauxBatch, Iterable<Account>, Iterator<Account> {
account[] accounts;
public Iterable<Account> start(Database.BatchableContext bc) {
return this;
}
public boolean hasNext() {
return !accounts.isEmpty();
}
public iterator<account> iterator() {
return this;
}
public account next() {
return accounts.remove(0);
}
public void execute(database.batchablecontext bc, account[] records) {
}
public void finish(database.batchablecontext bc) {
}
public void initialize(Account[] records) {
accounts = records;
}
}
Execute Anonymous
FauxBatch b = new FauxBatchImpl();
b.initialize([SELECT Id, Name FROM Account]);
Database.executeBatch(b);
Logs From Execution
30.0 APEX_CODE,ERROR;APEX_PROFILING,FINEST;CALLOUT,ERROR;DB,ERROR;SYSTEM,ERROR;VALIDATION,ERROR;VISUALFORCE,ERROR;WORKFLOW,ERROR
Execute Anonymous: FauxBatch b = new FauxBatchImpl();
Execute Anonymous: b.initialize([SELECT Id, Name FROM Account]);
Execute Anonymous: Database.executeBatch(b);
20:26:24.140 (140607767)|EXECUTION_STARTED
20:26:24.140 (140617897)|CODE_UNIT_STARTED|[EXTERNAL]|execute_anonymous_apex
20:26:24.326 (326375736)|FATAL_ERROR|Internal Salesforce.com Error
20:26:24.220 (326531141)|CUMULATIVE_LIMIT_USAGE
20:26:24.220|LIMIT_USAGE_FOR_NS|(default)|
Number of SOQL queries: 1 out of 100
Number of query rows: 23 out of 50000
Number of SOSL queries: 0 out of 20
Number of DML statements: 0 out of 150
Number of DML rows: 0 out of 10000
Maximum CPU time: 0 out of 10000
Maximum heap size: 0 out of 6000000
Number of callouts: 0 out of 10
Number of Email Invocations: 0 out of 10
Number of fields describes: 0 out of 100
Number of record type describes: 0 out of 100
Number of child relationships describes: 0 out of 100
Number of picklist describes: 0 out of 100
Number of future calls: 0 out of 10
20:26:24.220|TOTAL_EMAIL_RECIPIENTS_QUEUED|0
20:26:24.220|STATIC_VARIABLE_LIST|
FauxBatch:_static_b:0
20:26:24.220|CUMULATIVE_LIMIT_USAGE_END
20:26:24.326 (326675319)|CODE_UNIT_FINISHED|execute_anonymous_apex
20:26:24.326 (326685358)|EXECUTION_FINISHED
If I change executeBatch to scheduleBatch, the job shows up in the queue, but never executes; I have to abort it.
Test Method
Next, I created a test method for the class/interface.
@isTest(SeeAllData=true)
public class FauxBatchImplTest {
static testMethod void test() {
FauxBatch b = new FauxBatchImpl();
b.initialize([select id, name from account]);
Test.startTest();
Database.executeBatch(b);
Test.stopTest();
}
}
Results:
Time Started 7/16/2014 8:38 PM
Class FauxBatchImplTest
Method Name test
Pass/Fail Fail
Error Message Internal Salesforce Error: 411786643-886372 (-666072638) (-666072638)
Stack Trace