You need to sign in to do that
Don't have an account?
Katherine Rowe
Need an example of an unhandled exception
I need a trigger that will throw an unhandled exception. I'm new to writing triggers, can someone help me whip one up? I'm testing the emails that SF sends out to the last modified user on the trigger, when there is an unhandled exception.
It can be really simple. I just want to be able easily fire the trigger in SF and for it to throw an unhandled exception.
TestUtils.cls
MyTrigger.trigger
MyTriggerTest.cls
I know it seems a bit complicated, but I assure you it's worth the time and will make your code more robust in the long run.
All Answers
[1] http://pcon.github.io/presentations/testing/#exceptional-unknown-class-pre
[2] http://pcon.github.io/presentations/testing/#exceptional-unknown-class-post
[3] http://pcon.github.io/presentations/testing/#exceptional-unknown-test
That was a little above me, and it seems to involve creating classes? I was envisioning somethign easier.
Can I not just write a trigger something like this? This is just pseudo code, I would need help writing this in apex that it would accept.
TestUtils.cls
MyTrigger.trigger
MyTriggerTest.cls
I know it seems a bit complicated, but I assure you it's worth the time and will make your code more robust in the long run.
Ok thanks! I got it working.
Question. I see the unhandled exception being display in red on the screen. But I'm only ocassionally get the emails that says an unhandled exception has happened. It kind of seems like it is sending me the email the first time that trigger causes an unhandled exception, but not anymore after that.
Why aren't I getting the emails every time the unhandled exception occurs? My trigger should have only run about 5 or 6 times today, so that doesn't sound like I'm hitting any kind of limit?
As for why you aren't getting the email everytime, I've seen the same behavior and I do wonder if it has something to do with how frequently the issue happens. IE only sending the same error email once a day. It might be worth trying this new feature [1] that was introduced in Winter '16 and configuring the Exception mails to see if it changes anything.
[1] http://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/rn_apex_exception_emails.htm
Ok, I had read other posts where users had the same problem, not getting the emails every time. I guess that's the current behavior for everyone then.
I just tried adding myself to the Apex Exception Email list, but that doesn't seem to fix the "dont' receive emails everytime" problem.
Just wanted to know if we have a way of catching the unhandled exception (This is just one occurrence.).
We are can easily recreate this issue by trying to set the password of an inactive user.
Our approach is to deactivate the user if he does not login to the system for a period of 6 months.
So, once the deactivated user tries to login to his/her customer portal and tries to reset his/her password in order to login, we get the exception being caught.
Code to recreate the issue.
Step-1: Find an inactive user.
Step-2: Pass the user id and new password to the code as "System.setPassword('userId','newPassword');"
Though we have a workaround for this solution, I just wanted to know if there are any ways of finding/trapping such issue through a try-catch or some other mechanism?