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
jjatolunajjatoluna 

Can you make addError() in custom before delete trigger show in red. ?

The addError() behavior in a before delete trigger results in a message on the Home tab:

 

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 .Contacts cannot be deleted

 

 

I want it to stay on the same tab as the delete button and display at the top in red like this

 

                              Error: Invalid Data.
Review all error messages below to correct your data.
                      Contacts cannot be deleted

 

Note that addError() in a before insert trigger does put the message in red at the top (when not specifying a field)

 

Here is my simple before delete trigger code:

 

trigger contactDeleteTrigger on Contact (before delete)
{
     for (Contact c: Trigger.old)
     {
         c.addError('Contacts cannot be deleted');
     }
}



Best Answer chosen by Admin (Salesforce Developers) 
yvk431yvk431

Using stadard  page we can have these kind of messages only when we save info  , but we cannot have this for delete actions as the page will be redirected to some predefined page. The only way is to customize the detail page usign visual force and there we can have own custom validation. 

 

 

--yvk

All Answers

yvk431yvk431

Using stadard  page we can have these kind of messages only when we save info  , but we cannot have this for delete actions as the page will be redirected to some predefined page. The only way is to customize the detail page usign visual force and there we can have own custom validation. 

 

 

--yvk

This was selected as the best answer
jjatolunajjatoluna

OK Thank You

pramod sharma 15pramod sharma 15
I have used similar code as above for before insert and I'm getting system exception message instead of the user defined messge in adderror. why?