I have a custom button (JavaScript) which copies the Description field from Event to my custom Object like this:

summary.Discussion_Topics__c = '{!Event.Description}';

Both fields are of Long Text Area(32000) type. The button works fine when the Description has one line. When it includes multiple lines the javascript throws an exception. I would like to retain the formatting and copy the Description with multiple line. Can that be achieved? How?

1 Answer 1


The JSENCODE Visualforce function will escape the line feeds and other unsafe characters:

summary.Discussion_Topics__c = '{!JSENCODE(Event.Description)}';

This works in custom button JavaScript too e.g. in a custom "Execute JavaScript" button on Account:

var d = '{!JSENCODE(Account.Description)}';
  • Does JSENCODE available for a custom button JS?
    – Dedo
    Commented Nov 2, 2014 at 17:01
  • @Dedo Yes - see the example I added to the answer.
    – Keith C
    Commented Nov 2, 2014 at 17:15

You must log in to answer this question.

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