I have a custom button called massdelete on listview. I don't want everyone to see this button but only selected profiles or roles..How to do this?

Thanks in Advance..

  • Is it a custom button setup to "Execute Javascript" ? – Mike Katulka Apr 14 '15 at 19:52

You said the button execute's javascript. So, in the javascript code itself is where you first need to check the current user, maybe by profile, and give the ability or restrict using an alert message. You can use something like {!$Profile.UserType} == 'Profile Name ABC' in the JS code, really any of the $Profile or $User fields that make sense for your need.

Further, you can use custom settings too, like the hierarchical settings if you need to get more granular. And reference the custom settings in that button editor screen.

If you need to hide the button:

Restricting the visibility of the button is not possible in any "supported" way. Best bet is to use the alert. Otherwise you have 2 options at minimum I can think of that are pretty involved:

  1. Re-create the list view page, and manage the view drop-down on your own.. pretty involved: Custom List View to display VF Page

  2. In the button code itself, you can follow this methodology to onload hide the button:

    • Behaviour = "Execute JavaScript"
    • Content Source = "Onclick JavaScript" (don't get irritated, you won't have to click!)
    • at the body enter {!REQUIRESCRIPT("/resource/1402932484000/YourStaticResourceName")}
    • In the staticresource js file, perform the permission check/hide button.
  • Can i restrict even showing the button itself instead of showing an alert message 'You don't have rights' after clicking on the button. – graham Apr 14 '15 at 20:04
  • Ok so restricting the visibility of the button is not possible if this button is on a standard list view page. Well, currently it's not possible in any "supported" way. see updated answer – Mike Katulka Apr 14 '15 at 20:10
  • Re: (2), it will be deleted in Summer '15. However, a button can include code that can run onload (via {!REQUIRESCRIPT()}). You can put code in here to find the button, check permissions, and disabled/remove itself from the view. – sfdcfox Apr 14 '15 at 20:28
  • @sfdcfox I like your option..I will try that and update on how it goes.. – graham Apr 14 '15 at 20:42
  • Ah yes, same principle of (2) easily applied to the button code itself.. didn't tie that together. sfdcfox has some pre-pre-release info it sounds like.... I'm waiting 9 more days for the notes ;) – Mike Katulka Apr 14 '15 at 20:46

There once lived (prolly still lives) a sorcerer who taught us this secret recipe: Changing the color of a custom button

Follow this link to implement the same

I created a javascript function to hide the button as below

(function() {
  var button = document.getElementsByName('list_view_button_hide')[0];
  button.style.display = "none";

Encoded this to base 64 using http://rot47.net/base64encoder.html and used {!REQUIRESCRIPT("data:application/javascript;base64,your based encoded value")}

enter image description here


If you want to restrict the visibility of the Mass Delete button you can replicate the Javascript logic within the visualforce page and restrict user access to the visualforce page at a profile or permission set level.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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