Can batchable custom iterables support null values?
The only way I was able to get a null Iterable was to decorate it with an actual class.
I made a simple custom Decorator class like this one.
global class BatchableInteger
{
Integer BatachIntegerValue { get; private set; }
public BatchableInteger(Integer integerInBatch) { BatachIntegerValue = integerInBatch; }
}
Then I used it like your example.
public class BatchOverlay implements Database.Batchable<BatchableInteger>, Iterable<BatchableInteger>, Iterator<BatchableInteger>
{
List<BatchableInteger> BatchIterables { get; private set; }
public Iterator<BatchableInteger> iterator() { return this; }
public Boolean hasNext() { return !BatchIterables.isEmpty(); }
public BatchableInteger next() { return BatchIterables.remove(0); }
public Iterable<BatchableInteger> start(Database.BatchableContext batchContext)
{
BatchIterables = new List<BatchableInteger>();
List<BatchableInteger> temporaryIntegerList = new List<BatchableInteger>();
for(Integer index = 0; index < 5; index++)
BatchIterables.add(new BatchableInteger(null));
for(Integer index = 0; index < 10; index++)
{
temporaryIntegerList.add(new BatchableInteger(index));
if(temporaryIntegerList.size() == 5)
{
BatchIterables.addAll(temporaryIntegerList);
BatchIterables.addAll(temporaryIntegerList);
temporaryIntegerList.clear();
}
}
for(Integer index = 0; index < 5; index++)
BatchIterables.add(new BatchableInteger(null));
return this;
}
public void execute(Database.BatchableContext batchConext, List<BatchableInteger> scope)
{
System.debug(LoggingLevel.ERROR, scope.size());
System.debug(LoggingLevel.ERROR, scope);
}
public void finish(Database.BatchableContext batchContext) { }
}
I imagine the loss of the null value has to do with the serialization process. It happens with JSON serialization too, so I imagine there is something similar going on.