You need to sign in to do that
Don't have an account?

How to display an exception message from a trigger exception?
Hi All,
I am a newbie.
Before inserting or updating an opportunity, I have a trigger that fires and checks for a certain condition, i.e. the opportunity company must have at least a contact. If the trigger throws an exception, how can I catch the exception in the Opportunity panel/page so that i can display an alert instead of an ugly message seen below?
If an alert is not possible, then how can I make the error message looks nicer (just show the exception message) like below?
If you have a better idea, please share it here.
Thanks.
I am a newbie.
Before inserting or updating an opportunity, I have a trigger that fires and checks for a certain condition, i.e. the opportunity company must have at least a contact. If the trigger throws an exception, how can I catch the exception in the Opportunity panel/page so that i can display an alert instead of an ugly message seen below?
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger CheckContactTrigger caused an unexpected exception, contact your administrator: CheckContactTrigger: execution of BeforeInsert caused by: MissingCompanyContactException.MissingCompanyContactException: The company "Rajan Co" must have a contact.: Trigger.CheckContactTrigger: line 7, column 18
Review all error messages below to correct your data.
Apex trigger CheckContactTrigger caused an unexpected exception, contact your administrator: CheckContactTrigger: execution of BeforeInsert caused by: MissingCompanyContactException.MissingCompanyContactException: The company "Rajan Co" must have a contact.: Trigger.CheckContactTrigger: line 7, column 18
If an alert is not possible, then how can I make the error message looks nicer (just show the exception message) like below?
Error: Invalid Data.
Review all error messages below to correct your data.
The company "Rajan Co" must have a contact.
Review all error messages below to correct your data.
The company "Rajan Co" must have a contact.
If you have a better idea, please share it here.
Thanks.
Trigger.old[0].addError('can\'t delete this account.');
But it will show the error on next page.