2

I'm using Database.update in my batch class. This is wrapped around by a try/catch block. When I run the batch job some error occurs which is caught as I'm throwing a custom exception and catching it. But the 'finish' method from my batch class doesn't get invoked at all. Why is that? What am I doing wrong here? below is my code from my execute method. I'm able to reach till

System.debug('Errors size-'+updateErrors.size(); 

code:

try{          
    List<Contact> contacts = new List<Contact>();          
    contacts.addAll(list_contacts);          
    updateResult = Database.update(contacts ,false);          
    for(Database.SaveResult ir : updateResult ){ 
       if(!ir.isSuccess()){                     
         throw new ContactUpdateException('Contact UpdateException:'); 
         }             
       }          
}              
catch(ContactUpdateException e){          
     for (Database.SaveResult ir : updateResult ) {  
         //Operation failed, so get all errors    
           for(Database.Error err : ir.getErrors()){ 
              Error = 'Failed Store --'+ '  ' + ir.getId();
              updateErrors.add(Error);  
              System.debug('Errors size-'+updateErrors.size();
              }   
          }          
}          
catch(Exception e){}   

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.