Apex
global class BatchApex implements Database.Batchable<Integer> {
// Data to process
private List<Integer> numbers;
// Constructor to initialize the data
global BatchApex(List<Integer> numbersToProcess) {
numbers = numbersToProcess;
}
// Start method where we pass the collection as iterable
global Iterable<Integer> start(Database.BatchableContext BC) {
return numbers;
}
// Process the scope
global void execute(Database.BatchableContext BC, List<Integer> scope) {
for (Integer num : scope) {
// Create a single contact
Contact con = new Contact();
con.LastName = 'Test' + num; // Assign a unique name
con.Email = 'enginsalesforce@gmail.com'; // Assign a test email
insert con;
}
}
// Finish method
global void finish(Database.BatchableContext BC) {
System.debug('Batch processing completed.');
}
}
Video
Video does not exists.