3

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 ? – Samuel De Rycke Jun 24 '14 at 7:19
3

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? – SalesforceAspiration Jun 24 '14 at 7:41
7

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. – SalesforceAspiration 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. – Samuel De Rycke Jun 24 '14 at 16:35
1

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.