Posts

Showing posts from March 25, 2017

Save the Batch Error Job ID in Custom Object in case of Failure

Requirement :  Get the Failure record when processing thru batch Class Solution : Create a custom object for saving batch log errors and create a batch class   Custom Object: Batch_Log_Error__c  Custom Fields : Job_id__c,Record_Id__c,Error__c global class BatchClassName implements Database.batchable<sObject>,Schedulable{ String query ; // define Constructor global BatchClassName(){  query = 'Select id from SobjectapiName'; }  // Start Method Call    global Database.QueryLocator start(Database.BatchableContext BC){         return Database.getQueryLocator(query);    }        //  Execute Method Call global void execute(Database.BatchableContext bc, List<SobjectapiName> scope){ // Declare SobjectList and BatchErrorLoglst  list<SobjectapiName> lstofsobject  = new list<SobjectapiName>(); list<Batch_Log_Error__c> lstObjBatchLogError = new list<Batch_Log_Error__c>() try{ for(SobjectapiName obj :sco