function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC_DeveloperSFDC_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.
sbbsbb
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.