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..
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:
Re-create the list view page, and manage the view drop-down on your own.. pretty involved: Custom List View to display VF Page
In the button code itself, you can follow this methodology to onload hide the button:
{!REQUIRESCRIPT()}
). You can put code in here to find the button, check permissions, and disabled/remove itself from the view.
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")}
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.