Possible to add a clickable URL using ApexPages.addMessage

Is it possible to add a clickable url using ApexPages.addMessage? I am using ApexPages.addMessage to show an information alert but I would like to include a dynamically generated URL within the ApexPages.addMessage. The URL would be to a record within the same org.

Something like:

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Potential duplicate'+<a href="/o.Id">Click Me</a>))

I guess if this isn’t possible then I will need to add my own pageBlockTable which only renders when it has a value.

Answer

That should be possible. You would want to change it to be more like this though:

ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Potential duplicate <a href="' + o.Id +'">Click Me</a>'));

The markup will just be part of the String.

You also need to render the apex:pageMessage with escape="false" for the HTML to be rendered properly.

Attribution
Source : Link , Question Author : Girbot , Answer Author : Jesse Altman

Leave a Comment