You need to sign in to do that
Don't have an account?
ckemp
Testing for a System Administrator with JavaScript
I have a custom button that I have created that will call a web service. I want the button to only work for System Administrators, so I added this JavaScript to the button with an OnClick event:
This works just fine when I'm running it in my Developer's sandbox as a System Administrator and gives me the alert message when I am not a sysadmin. However, when I install this in production it gives me the "You do not have sufficient privileges to do this" message no matter what type of user I'm logged in with, including System Administrators. Does anyone know what's going on? Is there a different/better way to test whether the user is a sysadmin or not with JavaScript?
Code:
if (typeof(sforce) != "undefined") {
result = sforce.apex.execute("MyNamespace/MyWebService", "action", {ids : idsToSend}); } else { alert("You do not have sufficient privileges to do this."); }
This works just fine when I'm running it in my Developer's sandbox as a System Administrator and gives me the alert message when I am not a sysadmin. However, when I install this in production it gives me the "You do not have sufficient privileges to do this" message no matter what type of user I'm logged in with, including System Administrators. Does anyone know what's going on? Is there a different/better way to test whether the user is a sysadmin or not with JavaScript?
Usually when I restrict code to System Administrators, I use the profile name:
There are several other ways of restricting the use of buttons: