How can I add an email id as a hyperlink in a error message in a trigger?
3 Answers
You shouldn't.
Triggers are executing when your data is manipulated, from whatever context (UI or API). It would be a bad design to assume which interface is the source of your trigger execution and create user specific messages at that point.
That beeing said, that doesn't always applies to salesforce, as for standard pages you don't have the luxery of running custom controllers, and validation rules kinda skip the same principle.
ALSO: mailto hyperlinks are not perceived as user friendly by most users and often only work well with device installed email clients, and not with web email clients (I believe).
-
You are right Samuel.Emaito: is not working.Though it is coming as hyperlink,but onclick it is not going to the web mail page.is there any work around for this? Commented Jun 24, 2014 at 7:41
Use addError(String, Boolean)
with false
to the second parameter so that it'll not escape HTML
markups in your string message.
obj.addError('ERROR:<a href=\'your_link\'>More details</a>', false);
Found this similar post on success community.
-
Thanks highfive.It id working.But onclick on the hyperlink it is not going to the email page. Commented Jun 24, 2014 at 7:36
-
1The answer is just to explain how we can apply
HTML
formatting with theaddError
method. As @SamuelDeRycke has mentioned mailto hyperlinks are not going to be work well always without email clients– highfiveCommented Jun 24, 2014 at 8:01 -
1I think this should be the accepted answer to the question tbh. Commented Jun 24, 2014 at 16:35
-
This solution works in Classic but the escape parameter is ignored in Lightning. Hopefully Salesforce either fixes this in Lightning or creates another method of passing a hyperlink back in an error.– nbrownCommented Nov 10, 2020 at 21:19
You can use apex:pageMessage tag with escape="false" then use try catch to catch the error from trigger and format the error putting html tags for email id. Now apex page message will display hyper link