Follow Us:
Often times, things are never as simple as they seem when beginning a portion of a project. Recently, I was asked to create a button on a Salesforce.com form that would take data from the existing form and create a new Salesforce Lead record from it. Sounds simple enough, right? Sure, there is the all the preliminary work of gather requirements, understanding the existing business rules and application rules, but still pretty straight forward.
I began mapping out the fields to be translated to the new Lead record. A good number of them were picklist fields, a few were numeric fields and a couple fields were free text fields between 2000 and 3200 characters in length. So far so good. The client supplied test data and test records so I began my routine testing methodology. All went well, so I passed it on to the client for UAT (user acceptance testing). The client was happy, so, it was time to deploy to production.
Deployment went smoothly and users were beginning to use the new functionality. However, intermittently an error was being produced with a somewhat unclear message. Something was being seen as an unclosed string. Why was it intermittent and where was the unclosed string? It took a little poking around to discover that, on certain records, users were adding special characters to the free text fields. Somehow, this scenario was never tested for, or considered by the client. I tried the usual Find/Replace functions available, but none of them would work. After a bit more research I discovered the encoding function JSENCODE.
This function is a sort of all-purpose function for encoding text in order to make it play nice in JavaScript. Wrapping your text around JSENCODE allows you to capture quotes, apostrophes, line feeds, carriage returns, etc. and translate them within the text in your JavaScript code. If you’re working in the Salesforce scripting window of a form or code behind a button of a form, the JSENCODE function does not appear in the list of available functions. Hopefully this blog will help someone else find a solution quickly when facing the same intermittent error from your JavaScript in Salesforce.
The complementary paper includes over 12 years of research, recent survey results, and CRM turnaround success stories.
Request Download
This 60-second assessment is designed to evaluate your organization's collaboration readiness.
Learn how you rank compared to organizations typically in years 1 to 5 of implementation - and which areas to focus on to improve.
This is a sandbox solution which can be activated per site collection to allow you to easily collect feedback from users into a custom Feedback list.
Whether you are upgrading to SharePoint Online, 2010, 2013 or the latest 2016, this checklist contains everything you need to know for a successful transition.