You need to sign in to do that
Don't have an account?
fiona gentry
Test class for Batchable to insert records, iterate over the results, and persist information about any failures to the database
Hi Gurus,
Need a Test class for Batchable class with database.insert function then saves the results and iterate through each results
Need a Test class for Batchable class with database.insert function then saves the results and iterate through each results
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); } System.debug('ERT Case No is =====>' +listCTD); insert listCTD; Database.SaveResult[] srList = Database.insert(listCTD, false); // Iterate through each returned result for (Database.SaveResult sr : srList) { if (sr.isSuccess()) { // Operation was successful, so get the ID of the record that was processed System.debug('Successfully inserted Case_Type__c: ' + sr.getId()); } else { // Operation failed, so get all errors for(Database.Error err : sr.getErrors()) { System.debug('The following error has occurred.'); System.debug(err.getStatusCode() + ': ' + err.getMessage()); System.debug('Case_Type__c fields that affected this error: ' + err.getFields()); } } } } global void finish(Database.BatchableContext BC) { // execute any post-processing operations } }
Refer this URL -> https://apexcoder.com/2016/11/08/how-to-write-test-class-for-batch-apex-in-salesforce/
All Answers
Refer this URL -> https://apexcoder.com/2016/11/08/how-to-write-test-class-for-batch-apex-in-salesforce/