enter image description here {!REQUIRESCRIPT('/soap/ajax/39.0/connection.js')}

var rec = 
if(rec != "--None--" ) {
HYPERLINK("/apex/Apttus__AgreementCancel?id=" &Id, 
IMAGE("/resource/Apttus__Button_CancelRequest", "Cancel Request"), "_self");
else {
alert('You cannot do this');

ERROR-<span class="validStyle">No syntax errors in merge fields or functions. 

1 Answer 1


Your merge field needs to be quoted and escaped:

var rec = {!Apttus__APTS_Agreement__c.Reason_for_cancelation__c};

just dumps the value of the field directly into the JavaScript, likely producing syntax errors. It should be

var rec = '{! JSENCODE(TEXT(Apttus__APTS_Agreement__c.Reason_for_cancelation__c)) }';

JSENCODE() escapes backslashes for you.

The HYPERLINK() and IMAGE() functions are not defined outside of a merge field context {! }, but aren't meaningful here in a JavaScript button anyway. It's not clear what you're aiming to do; if you wish to do a redirect, do it via JavaScript rather than attempting to use a merge function. If you're aiming to generate content to insert in the page, you may want a formula field or an embedded Visualforce page.

  • <span class="errorStyle">Error: Field Apttus__APTS_Agreement__c.Reason_for_cancelation__c is a picklist field. Picklist fields are only supported in certain functions. <a href="javascript:openPopupFocusEscapePounds('help.salesforce.com/apex/…', 'Help', 1024, 768, 'width=1024,height=768,resizable=yes,toolbar=yes,status=yes,scrollbars=yes,menubar=yes,directories=no,location=yes,dependant=no', false, false);">Tell me more</a></span>
    – raj blp
    Aug 8, 2019 at 11:33
  • Thanks @David Reed . Picklists are not supporting ,Is there any workaround for this ?
    – raj blp
    Aug 8, 2019 at 11:36
  • Wrap it in a TEXT() call, as always with picklist fields.
    – David Reed
    Aug 8, 2019 at 11:36
  • No syntax errors ,But on page its displaying errors as showing in the screenshot above. Please can you look in it .
    – raj blp
    Aug 8, 2019 at 11:54

You must log in to answer this question.

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