You need to sign in to do that
Don't have an account?
SFDC_Developer
Catch block coverage in test class
I have a class where I am using exception handling, but my test class is not covering the exception block.
try {
dbAccountUpdateResult = Database.update(mapAccount.values());
dbContactUpdateResult = Database.update(mapContact.values());
}
catch (DMLException e)
{
UTIL_LoggingService.logDmlResults(dbAccountUpdateResult,null, null , null, CLASSNAME, METHODNAME, null);
UTIL_LoggingService.logDmlResults(dbContactUpdateResult,null, null , null, CLASSNAME, METHODNAME, null);
}
Here "UTIL_LoggingService" is my class which is used for exception handling and "logDmlResults" is my method name.
try {
dbAccountUpdateResult = Database.update(mapAccount.values());
dbContactUpdateResult = Database.update(mapContact.values());
}
catch (DMLException e)
{
UTIL_LoggingService.logDmlResults(dbAccountUpdateResult,null, null , null, CLASSNAME, METHODNAME, null);
UTIL_LoggingService.logDmlResults(dbContactUpdateResult,null, null , null, CLASSNAME, METHODNAME, null);
}
Here "UTIL_LoggingService" is my class which is used for exception handling and "logDmlResults" is my method name.
sbb
I would create a test case to force Database.update() to fail, such as not providing a value to a required field, or something like that.