Batch Exception Handling

BatchException allows you to catch and collect all business rule exceptions without stopping the batch create/update transaction. After the whole batch create/update is processed, the data transaction is still rolled back but BatchException provides you a list of business rule exceptions that occurred during the process. Looping through the exception list, you can identify the problematic business objects. You might want to remove those from the transaction list and rerun the batch update/create again. Or you might want to fix the issue and rerun the batch update/create again.

Example: Catching BatchExceptions and looping through the exception list:

try

{

// call update or create here... ...

}

catch ( BatchException e )

{

// Display stack trace of batch exception

e.printStackTrace();

System.out.println();

// Display index and exception message of all exceptions in the batch exception

List exceptions = e.getExceptionList();

for ( int i = 0; i < exceptions.size(); i++ )

{

ServerException se = (ServerException)exceptions.get(i);

System.out.println( se.getSource() + " - " + se.getMessage() );

}

}



Legal Notices | Your Privacy Rights
Copyright © 2003, 2020

Last Published Tuesday, December 8, 2020