Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created this simple visualforce page, using google charts. Everything works great until there is a comment in the rating with an apostrophe ('). I have tried using the JSENCODE, but it is still not working - any suggestions?

The below works fine with no apostrophes - but renders nothing when there is one. (in the child2.Rating_Type__c field.

<apex:page standardController="Account" showheader="false">
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <script type="text/javascript" src="//"></script>
    <script type="text/javascript">
      google.load('visualization', '1', {packages: ['table']});
    <script type="text/javascript">
       function drawVisualization2() {
      // Create and populate the data table.
         var data2 = google.visualization.arrayToDataTable([
          ['Contact Name', 'Date', 'Rating Type', 'Rating', 'Comments', 'Rating Status'],
           <apex:repeat value="{!Account.Product_Ratings__r}" var="child2">

               ['<a href="{!}">    {!child2.Contact_Name_Text__c}</a>',
               '{!child2.Rating__c}', '{!JSENCODE(child2.Comments__c)}',

      // Create and draw the visualization.
      visualization = new google.visualization.Table(document.getElementById('ratings'));
      visualization.draw(data2,{allowHtml: true, page: 'enable', pageSize: '25'});


  <body style="font-family: Arial;border: 0 none;">
    <div id="ratings"></div>

share|improve this question
up vote 4 down vote accepted

The simplest approach would probably be to encapsulate it in double quotes so that you don't need to worry about escaping a string with single quotes in it.

e.g. "{!child2.Rating_Type__c}" instead of '{!child2.Rating_Type__c}'

share|improve this answer
I did notice that I had the wrong field name - should be '{!JSENCODE(child2.Comments__c)}'. Updated the code above. I tried "{!child2.Comments__c}" worked perfectly. Thanks! – Merry Mar 10 '14 at 22:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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