I want to prevent users from being redirected when they click a button and picklist value is false.

I have a custom button on Opportunity related list on account. If the value of Account type is 'OLD', users should get an error message and not redirect the page. If it's anything else, they can be redirected opportunity.

What is the best way of going about this?

Thanks, -Kenn

1 Answer 1


In the custom button, do something like this:

if("{!JSENCODE(Entity.Field)}"==="OLD") {
    alert("You cannot use this button on this account.");
} else {
    window.top.location.href = "(url to go to)";

For a picklist, you can use ISPICKVAL:

if({!ISPICKVAL(Entity.Field,'OLD')}) {
    alert("Access denied.")

Make sure the type is set to "Execute JavaScript".

  • Thanks a lot. Might you know the proper syntax in the situation where I have a picklist instead of a text field? Not sure how the ISPICKVAL arguments should be implemented.
    – Kenn K
    Commented Jul 5, 2013 at 20:20
  • I've updated the code to reflect how you can use ISPICKVAL for picklist values.
    – sfdcfox
    Commented Jul 5, 2013 at 21:07
  • Hi there, is there a less intrusive to display a notification instead of using alert() ?
    – dzh
    Commented Jul 8, 2014 at 13:49
  • You have full JavaScript access in a button. This means you could write as elaborate code as you wanted. Import your favorite library and show a lightbox, or change the label on the button, or do some cute little animation. The sky's the limit, though this answer was intentionally plain.
    – sfdcfox
    Commented Jul 8, 2014 at 15:26

You must log in to answer this question.

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