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

Before delete, better error message
I've been searching around, but have yet to find the solution. I have the trigger below that prevents the case from being deleted if the work order count field is > 0. The problem is that it shows a somewhat harsh system error message vs. a nice popup window that the user can click ok on. Any suggestions?
trigger BeforeDeleteCase on Case (before delete) { for (Case cs : trigger.old) { if (cs.Work_order_count__c > 0) //if the work order count is more than zero { cs.addError('Can delete this case, A work order for this case currently exists'); } } }
Validation Errors While Saving Record(s) There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Can delete this case, A work order for this case currently exists". Click here to return to the previous page.
Hi Ben,
When you delete a case, the system redirects you to another URL and therefore the error message that you are trying to display with the trigger will always be displayed in the way that it is being shown currently.
If the main purpose here is to show the error message via the UI, then you can create a custom Delete button to manage the requirement. You can use the following steps:
1. Disable the trigger that you have coded
2. Create a custom button with the Display Type as Detail Page Button and the Content Source as OnClick JavaScript
3. Add the following code:
4. Add the custom Delete button the page layouts.
I hope this helps. In case you have any queries, feel free to ask.
All Answers
Hi Ben,
When you delete a case, the system redirects you to another URL and therefore the error message that you are trying to display with the trigger will always be displayed in the way that it is being shown currently.
If the main purpose here is to show the error message via the UI, then you can create a custom Delete button to manage the requirement. You can use the following steps:
1. Disable the trigger that you have coded
2. Create a custom button with the Display Type as Detail Page Button and the Content Source as OnClick JavaScript
3. Add the following code:
4. Add the custom Delete button the page layouts.
I hope this helps. In case you have any queries, feel free to ask.
I'll probably do as you stated and might also make another button to allow me to delete the record no matter what.