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
benburbbenburb 

Escape html in apex:messages?

I'm trying to show all the errors in my VisualForce page using my own styling, so I include <apex:messages> at the top of the page (instead of <apex:pageMessages>) and add the appropriate styleClass attribute. It's working fine (was guided by http://salesforce.stackexchange.com/questions/8139/difference-between-the-multiple-messaging-options-in-visualforce).

Now I have a requirement to include a hyperlink in an error message itself, yet the 'escape='false'" attribute available in <apex:pageMessages> is not available in <apex:messages>.

Do I really have to choose between Salesforce styling with the ability to hyperlink an error message, my own styling without that ability, or rolling my own error messaging from scratch? Hoping I'm missing something.

Thanks for any ideas!
andy81andy81
you can use something like this to get a hyper link for apex:messages part.
<a href='URL'> <apex:messages/></a>

Here URL means a return url where you want to show some data regarding an error message.
benburbbenburb
Thanks Andy, but I'm trying to do something like:

            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 'That child is too old for the class. Click <a href="www.company.com/policy.html">here</a> to review our policies.');
            ApexPages.addMessage(msg);

using <apex:messages> (works fine with <apex:pageMessages escape="false">).
 
andy81andy81
you can use try catch block to get those messages.
follow this link which might be usefull for your question.
http://salesforce.stackexchange.com/questions/51072/what-controls-the-severity-of-apexpages-addmessagesexception
Pooja Agrawal 8Pooja Agrawal 8
Hi Ben, were you able to achieve this using <apex:messages>

ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 'That child is too old for the class. Click <a href="www.company.com/policy.html">here</a> to review our policies.');
 ApexPages.addMessage(msg);

I have similar requirements.