I've noticed that SFDC is not properly escaping some characters in the code it generates to be eval'd when using javascript custom buttons. For instance, say I have an object with a field that contains a line break. My code would look like:

var field = "{!Object__c.Field}";

The code SFDC generates would look like:

eval('var field = \"Field\r\nData\"');

This is invalid javascript and will return an error. However, if SFDC properly escaped the carriage return and linefeed characters, this code would behave as expected. Is there any way to fix this behavior?

1 Answer 1


Did you tried using the {!JSENCODE(text)} formula function.

You should declare var as:

var field = "{!JSENCODE(Object__c.Field)}";

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .