I have a batch job that does the following :
- Makes Http callout
- Create Cases
- Calls the next Batch job (In the finish function) i.e.
Batch
public void finish(Database.BatchableContext context) {
if (LOG_THIS_CLASS) System.debug('<Arcus> In the finish function of CaseCreation class.. ');
AsyncApexJob batchJob = [
SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedBy.Email
FROM AsyncApexJob
WHERE Id = :context.getJobId()
];
Integer jobs = [
SELECT COUNT()
FROM AsyncApexJob
WHERE JobType = 'Batch Apex'
AND Status IN ('Queued', 'Processing', 'Preparing')
];
Integer scopeSize = Limits.getLimitCallouts() - Limits.getCallouts();
System.debug('<Arcus> The scope size == ' + scopeSize);
if (jobs > 4) {
// try again in a minute
Datetime sysTime = System.now().addSeconds(60);
String chronExpression = '' + sysTime.second() + ' ' + sysTime.minute() + ' ' + sysTime.hour() + ' ' + sysTime.day() + ' ' + sysTime.month() + ' ? ' + sysTime.year();
CaseScheduler scheduledBatch = new CaseScheduler();
System.scheduleBatch(new AccountCaseLink(), 'Case Account Link' + sysTime, 1, scopeSize);
} else {
AccountCaseLink batch = new AccountCaseLink();
Database.executeBatch(batch, scopeSize);
}
}
The second batch job does another http callout based on the ids of the cases created and does account matching for each case. To test this, I have created a HttpCalloutMock and just set the mock in my test class. When tested I get error : System.NullPointerException: Attempt to de-reference a null object. Any help? Thanks