You need to sign in to do that
Don't have an account?
ashu 6112
Hi All,
I have to cover code coverage of catch block.
Please help:
catch block test coverage
public static Account insertIntoAccount(Account account){ try{ insert account; return account; }catch(Exception e){ string error = ExceptionLogger.createExceptionsRecord(e.getMessage(), 'DealReqContactController', e.getStackTraceString()); throw new AuraHandledException(error); return null; } }
Hi All,
I have to cover code coverage of catch block.
Please help:
But it is not covering the catch block, it is covering only the try block...
Below code might help
Here we are trying to insert already inserted account, so it will give an exception and go to the catch block.
Kindly mark this as the best answer if this helps.
we dont need to write the test catch block in our test class..
There 1 trick I use but I dont recommend this..
write catch in single line so it will be automatically covered
Dont getting y0our point, please gve suggestion.
try to write body of catch block in single line ..
Didn't the above solution given by me, work for you? Could you pls let me know what issue you faced for the above code for raising exception codition.
eg. catch(Exception ex){ system.debug('ERROR Occurred :: '+Ex.getMessages()); return null; }