I store raw HTML code in a rich text field in the backend. I query it out in the controller and try to render it as HTML in a VF page. It displays the whole HTML code, it dosent render itself as HTML. I have used escape = false in the output text. This was working properly when the field was a long text area. Please provide me a way to get it to 'escape' once again.

  • 1
    why don't you try <apex:outputField> ? – Ratan Paul Feb 1 '16 at 11:13
  • 1
    or you can go harder, use a hidden output field in visual force page, get value of the html field via JS, and apply that to certain page position. That's harder, but more flexible – kurunve Feb 1 '16 at 11:15
  • You should post some code if you want a precise answer to why things aren't working. – Robert Sussland Oct 24 '16 at 2:35

You can re-render the html code with JavaScript as shown in the example below. Rich_Text__c is a RichText field containing raw html code. Through jQuery the span tag is replaced by a div element with the raw html code created by jQuery. Now you can see rendered html in page.

VF Page

<apex:page controller="RichTextController" >
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <span id="inputtxt"/>
    <script type="text/javascript">


public class RichTextController {
    public String myText {get;set;}
    public RichTextController(){
        Book__c abook = [SELECT Rich_Text__c FROM Book__c where Id = 'a0Ii000000gKbw5']; 
        myText = abook.Rich_Text__c;
  • 1
    This will not pass security review if its appexchange app – Mohith Shrivastava Feb 1 '16 at 11:29
  • @MohithShrivastava Thanks for your comment, I have updated my answer. – Saroj Bera Feb 1 '16 at 14:09
  • 1
    This won't pass either.You have to HTML and JSENCODE your getter merge field – Mohith Shrivastava Feb 1 '16 at 14:18
  • Of course it can pass the Security Review. Rich Text fields are safe to render unescaped. – Robert Sussland Oct 24 '16 at 2:34
  • I have tried and did not work for me – Nick Kahn Dec 15 '16 at 21:53

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.