[SalesForce] Salesforce query on profile not working on user language change

I have a query on profile like profilename = [Select name from profile where id=:userinfo.getUserprofileid ].name Now I have a check in VF page like profilename == 'System Administrator' . this works fine if the logged in user language is english. If the user language is different then profile name will be 'System admin' in that language . So how to prevent this beahviour? Also is there any particular field in profile which I can use to identify the profile is system admin? so that I can have check on that field instead of checking for name which is causing the problem, for example I think modifyall filed is only checked for system admin.

Best Answer

You don't always to query in the controller for everything, some Profile fields are available in VF out of the box: {!$Profile.Name}.

This one is bit tricky because Profiles don't have DeveloperName field that can be used to identify record types for example. And we also don't have the "Custom?" checkbox exposed via API...

One idea would be to put something into the Description field (view the profile, then click "Edit properties").

Another would be

SELECT Id, Name, Description
FROM Profile
WHERE UserType = 'Standard' AND PermissionsAuthorApex = true

"Author Apex" means the "Modify All Data" and "View Setup and Configuration" are set too. This should deal with "power users" if you have any business people that need "Modify all data" (weird but then again I saw it few times) and even if you have some dedicated profiles for data integration user accounts - they probably won't need "Author Apex".

Last but not least - is profile creation day same with Org creation day would be a pretty good indication what's likely to be custom vs. standard ;)

Related Topic