I wrote a batch class to insert dummy data into big object and have used Iterable
to insert data.
I was under impression that Iterable
should only be able to insert in normal limit of 50K records.
But when I tried giving it 1 Millions, it processed even that. As this is the max I can insert in my developer edition.
Here is the sample :
global class BigObjectInsertHelper implements Database.Batchable<Integer> {
global Iterable<Integer> start(Database.BatchableContext param1) {
return new IntegerIterator(1000000);
}
global void execute(Database.BatchableContext param1, List<Object> param2) {
List<BigAccountRecord__b> bigAccountRecordBS = new List<BigAccountRecord__b>();
for (Integer i = 0; i < param2.size(); i++) {
BigAccountRecord__b accountRecordB = new BigAccountRecord__b();
accountRecordB.FirstName__c = 'Nagendra' + generateRandomString(5);
accountRecordB.LastName__c = 'Nagendra' + generateRandomString(5);
accountRecordB.Name__c = accountRecordB.FirstName__c + ' ' + accountRecordB.LastName__c;
accountRecordB.PersonalEmail__c = generateRandomString(6) + '@gmail.' + generateRandomString(3);
accountRecordB.Description__c = generateRandomString(40);
bigAccountRecordBS.add(accountRecordB);
}
Database.insertImmediate(bigAccountRecordBS);
}
global void finish(Database.BatchableContext param1) {
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
// Replace IDs with valid record IDs in your org.
message.toAddresses = new String[]{
UserInfo.getUserEmail()
};
message.subject = 'Batch Status';
message.plainTextBody = 'Finished with BigObject Insertion';
Messaging.SingleEmailMessage[] messages =
new List<Messaging.SingleEmailMessage>{
message
};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
if (results[0].success) {
System.debug('The email was sent successfully.');
} else {
System.debug('The email failed to send: ' + results[0].errors[0].message);
}
}
public static String generateRandomString(Integer len) {
final String chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
String randStr = '';
while (randStr.length() < len) {
Integer idx = Math.mod(Math.abs(Crypto.getRandomInteger()), chars.length());
randStr += chars.substring(idx, idx + 1);
}
return randStr;
}
}
Also, when I tried to pass 50 Million
/ 60 Million
in my Iterable, it starts preparing the batch for it. But it never gives an error saying Maximum record limit reached.
Though it fails while preparing the batch, I think this is because there is a time limit in which start
should return the result, 2 minutes
probably.
MY question is what is the limit of records which can be passed in Iterable
in a batch class? Like we have for QueryLocator
as 50 million max, do we have something for Iterable
too?