How can I add an email id as a hyperlink in a error message in a trigger?

  • Where should this show up ? Standard pages or visualforce pages ? Jun 24 '14 at 7:19

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? Jun 24 '14 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. Jun 24 '14 at 7:36
  • 1
    The answer is just to explain how we can apply HTML formatting with the addError method. As @SamuelDeRycke has mentioned mailto hyperlinks are not going to be work well always without email clients
    – highfive
    Jun 24 '14 at 8:01
  • 1
    I think this should be the accepted answer to the question tbh. Jun 24 '14 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.
    – nbrown
    Nov 10 '20 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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.