The Problem with Apostrophes in Hyperlinks

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.

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

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!