The Problem with Apostrophes in Hyperlinks

salesforce service cloud
Service Cloud Console Hyperlinks
April 12, 2013
contentment success
Contentment leads to Success
May 6, 2013

The Problem with Apostrophes in Hyperlinks

apostrophes problem
Applies to: Lightning and Classic

Today, I ran into a small problem with a link on a Visualforce page I had created. I had a Visualforce component with a table of account records. Some of the account record links worked perfectly, while others would not. I discovered the problem was with accounts with an apostrophe (‘) in their name. For example: McDonald’s or O’Kelly.

I’m sure there are guys out there who can explain the reason these apostrophes are problematic; I’m not that guy. I can just share what I found to resolve the problem. The solution is in the use of the JSENCODE( ).

JSENCODE( )? Why were you using javascript on links to begin with? Well, that is an issue for another post, but basically this page had to work within the Service Console. The Service Cloud Console has some crazy nuances that force you to do some things a bit differently. For more details, see my post titled, “Service Cloud Console Hyperlinks.”

The JSENCODE( ) function adds an escape character (ie: ‘/’ ) in front of the apostrophe so your account name will look more like: McDonald/’s or O/’Kelly.

So here’s a code snippet of how it would look. The openTab is the javascript call that processes the hyperlink.

</p><br /><p><apex:column headerValue="Account" style="width:400px"><br /><a href="#" onClick="openTab('{!sl.AccountId}','{!JSENCODE(sl.Account__r.Name)}'); return false">{!sl.Account__r.Name}</a><br /></apex:column><br />

Hope this helps you if you run into a similar problem. Be sure to share your insights and wisdom by commenting below.

Terry Miller
Terry Miller
Terry has spent over 20 years focused on business leadership and information technology. As an independent consultant, he enjoys working with a variety of customers to help them solve business problems using the Salesforce® platform. His ability to quickly identify bottlenecks and provide understandable solutions has gained him the trust of his customers. If you're looking for expert guidance on your next Salesforce® project, click here to contact Terry today.

1 Comment

  1. Billy Hansbrough says:

    I’m really enjoying the design and layout of your site. It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hire out a developer to create your theme? Superb work!

Leave a Reply