You need to sign in to do that
Don't have an account?
How to get 100% code coverage of an apex using try-catch block
I am unable to cover the catch block of this code.
![User-added image](/forums/servlet/rtaImage?eid=9062I000000XlvX&feoid=Body&refid=0EM2I000000e9g2)
@AuraEnabled public static ID getUserId() { try{ return userinfo.getuserid() } catch (Exception ex) { return ex.getMessage(); } }
I have gone through your code. I do not think that you can cover that catch block because to a cover catch block one needs to through an exception.
But your code contains just one line which is a standard method call and does not perform any calculation.
I would recommend removing the try-catch block from such a small class.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com