Here is my current Batchable apex code,currently this batch job copies the data over from the new custom object ERT_Case_Type__c to the old custom object Case_Type__c
But problem is this job not copying when the Level2 or Level3 are not there. I mean say Level2 or Level3 is NULL
How can i make sure that Batchable Salesforce apex code report the records which didn't got copied because there needs to be a matching set of L1, L2 and L3s in Case Type.
global class ertcopybatch3pm implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
// collect the batches of records or objects to be passed to execute
String query = 'select Case__c, Level_1__c, Level_2__c,Level_3__c FROM ERT_Case_Type__c';
System.debug('ERT Case No is =====>' +query);
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<ERT_Case_Type__c> exeList) {
// process each batch of records
List<Case_Type__c> listCTD = new List<Case_Type__c>();
System.debug('ERT Case No is =====>' +exeList);
for(ERT_Case_Type__c exe : exeList)
{
listCTD.add(new Case_Type__c(Case__c=exe.Case__c,Level_1__c=exe.Level_1__c,Level_2__c=exe.Level_2__c,Level_3__c=exe.Level_3__c));
// System.debug('ERT Case No is =====>' +Case__c);
}
try {
System.debug('ERT Case No is =====>' +listCTD);
insert listCTD;
} catch(Exception e) {
System.debug(e);
}
}
global void finish(Database.BatchableContext BC) {
// execute any post-processing operations
}
}
Thanks in advance, Carolyn