I added a custom account list button via SalesForce setup.

So, when I click on Accounts tab, then on All accounts on selectList, I have all my accounts and on the top my custom button.

I want to know if there is a way to disable this button until at least one account is checked and enable it when user check one or many accounts ?

EDIT : It seems to be impossible to do.

So I did a validation like this : display an alert if no object is selected and redirect to a custom page if at least one object is selected :

var ids = {!GETRECORDIDS($ObjectType.Account)};

if(ids.length > 0) {
} else {
    alert("No selection !");

But the problem encountered is if I have more than one ID, I have an error message saying me than an ID is composed by 15 characters only.

So how can I pass my ID (one or more) to my visualForce page to get them in my controller ?

1 Answer 1


Yes, you can! If you use a button which executes javascript, you can use require-script as described here http://help.salesforce.com/HTViewHelpDoc?id=customize_functions_i_z.htm#REQUIRESCRIPT to include a javascript e. g. from a static resource. The script will be executed right when the page loads and even if the button is not pressed at all.

So you could set the visibility with plain js or do it the convenient way and include jquery with some logic and event handler to toggel the buttons visibility.

If your respective button does not execute javascript, that's no problem either: Just introduce a second button or link which does and make this one control the visibility of the other on and hide itself always.


There was another (now deleted) answer which pointed to that link:http://abhithetechknight.blogspot.com.au/2013/09/concept-of-standardsetcontroller-for.html?m=1 since it shows how to pass ids to a set controller via a js button it's possibly helpful.

  • I don't use JavaScript. But if I want to add a hidden button that control the visibility, how can I retreive my first button ? I don't have any ID to get it !
    – SF_user
    Jul 28, 2014 at 13:03
  • Not necessarily. You can use jquery to scan for the label (which is value attr) or figure out selectors to get the sibling button by it's position in the DOM. Both not perfect but will work. But for most usecases you can simply switch to execute js and use this to do what ever you need, e.g. navigate to a visualforce page.
    – Uwe Heim
    Jul 28, 2014 at 13:09
  • Ok, thanks. I understand I can have a hidden button that hide my first button on page load. But how can I know when user check one or several checkboxes to show my button ?
    – SF_user
    Jul 28, 2014 at 13:15
  • Again jquery is your best friend. Although it could be done with pure JS, it's easy with jquery to scan for the checkboxes and determine if one-or-more or none is checked. And again, you won't need the exact IDs. It's even better to keep it loose-coupled, so the whole patter is reusable elsewhere. I use firebug to figure out selectors. Its fun! And yes it theoretically could break if salesforce may change the markup in the future but this happens rarely and even if it's very easy to fix.
    – Uwe Heim
    Jul 28, 2014 at 13:24
  • 1
    Put the invocation of test() at the end but inside the resource. Verify that the resource is loaded. Check out this salesforce.stackexchange.com/questions/38918/… on how to use require. It will work.
    – Uwe Heim
    Jul 28, 2014 at 14:10

You must log in to answer this question.

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