You need to sign in to do that
Don't have an account?

Detect if user is System Administrator
Hi there everyone.
Does anyone know of a way of detecting if the user is a system administrator?
I tried by comparing the user's profile name but I think this changes with the language and need multilanguage support.
Any ideas?
Thanks!
You could create a custom label (setup->create->custom label) and store the sys admin profile id in a label. You could then compare the user profile id with the label.
Id sysProfileId = Label.sys_admin_prof_id;
if (sysProfileId == UserInfo.getProfileId()) {
....
Whenever you deploy your code anywhere you will need a one off check that your ids are all correct for the target environment. Benefit is that you don't issue a query - nice especially in triggers where the governor limits are low.
If you are willing to accept that a user with "modify all data" permission is a system admin then this might help:
public static boolean isSysAdmin(String thisUserId) {
boolean isAdmin = false;
User thisUser;
try {
thisUser = [SELECT Profile.PermissionsModifyAllData
FROM User WHERE u.Id =: thisUserId];
isAdmin = thisUser.Profile.PermissionsModifyAllData;
} catch(Exception exc) {
//do nothing
}
return isAdmin;
}
and you can simply do a string comparison to know if the profile is system admin