Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question

1 Answer

up vote 4 down vote accepted

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".

share|improve this answer
 
Thanks, works like a charm! –  Kenn K Jul 3 at 23:35
 
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 Jul 5 at 20:20
 
I've updated the code to reflect how you can use ISPICKVAL for picklist values. –  sfdcfox Jul 5 at 21:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.