I am using Javascript code in Custom link to open a URL or display Error message based on the condition.

Behavior= Execute Javascript
Content Source= Onclick javascript

if('{object__c.field1__c}' <> 'Z0' || '{object__c.field1__c}' <> 'Z4')
window.alert("Error Message");

But, It is not working. Can anyone give suggestion please.

The following error is coming when I click on the custom link:


enter image description here

  • 2
    What is not working? Jun 20, 2018 at 13:15
  • I am getting error. I have added in question. Please check.
    – Ravindar D
    Jun 20, 2018 at 14:39

1 Answer 1


JavaScript does not use <> to mean "not equals." Instead, you could use !=, or you can even just use a formula. Also, make sure your merge fields are also in the {! ... } format. You're also confusing || with &&. With ||, if field1__c is Z0, then it will not be Z4; in other words, it would always evaluate to true! Here's a modified version of your code:

// Using merge formula!
if({!Object__c.Field1__c<>'Z0'&&Object__c.Field1__c<>'Z4'}) {
  alert('Error Message');
} else {

If you were not using a merge formula, it'd look like this:

if('{!Object__c.Field1__c}'!='Z0'&&'{!Object__c.Field1__c}'!='Z4') {

Note that this method is definitely not recommended; it's way too easy to make mistakes, and is definitely less readable than a simple formula.

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