You need to sign in to do that
Don't have an account?
Problem checking profile "system administrator"
Hi,
For a trigger, we need to check if the user running the code is the system administrator.
Now, we do the following:
Profile prof = [select Name from Profile where Id = :UserInfo.getProfileId() ];
// If current user is not a System Administrator, do not allow something
if (!'System Administrator'.equalsIgnoreCase(prof.Name)) {
// you are not authorized
}
The problem with this code is that if you have a non-english org or your user has his language set to non-english that this check will not work. (for example a French or Dutch org)
Is there another way to check if a profile is of type system administrator?
Thanks in advance for your responses.
Koen
I would use "PermissionsModifyAllData " field on profile to see if its System Administrator. (Be default you would have this permission checked to true).
I am assuming that you have only one profile (i.e, system admin) with this permission enabled.If you have any other custom profile with that permission enabled, the trigger would also execute for that user profile.
If( prof.PermissionsModifyAllData ==true){
//do your logic
}
Hope it helps.
Sales4ce
All Answers
I would use "PermissionsModifyAllData " field on profile to see if its System Administrator. (Be default you would have this permission checked to true).
I am assuming that you have only one profile (i.e, system admin) with this permission enabled.If you have any other custom profile with that permission enabled, the trigger would also execute for that user profile.
If( prof.PermissionsModifyAllData ==true){
//do your logic
}
Hope it helps.
Sales4ce
Hi,
Indeed, although it's not yet a waterproof solution, it is better then checking on the name.
Would be good though that there would be a way to check this independant on the language.
Thanks!
Koen