function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
wbrproductionswbrproductions 

Add error to Standard Object Detail page

I'm attempting to restrict the delete of a Contact, via before delete trigger, by looking for a specific value in a custom picklist field.

 

I've created a trigger, as follows (on Before Delete):

trigger ContactDelete on Contact (before delete)
{
static string errSecPointContact = 'This Contact is the Security Point of Contact on the Account, and cannot be deleted. Please contact the SFDC Admin group for any questions.';
for (Contact c : trigger.old)
{
if (c.Job_Role__c == 'Security Point of Contact')
{
c.addError(errSecPointContact);
}
}
}

 

This error message displays as follows:

"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 "This Contact is the Security Point of Contact on the Account, and cannot be deleted. Please contact the SFDC Admin group for any questions.".

Click here to return to the previous page. "

That's a pretty ugly solution. How can I go about adding this error to the standard object detail page, or display this error in a more user-friendly way?

 

Thanks!

Starz26Starz26

Try:

 

c.job_role__c.addError(....);