Has anyone figured out how to call the standard profile by name and still be language agnostic? Standard profiles get translated at run time and all options I can think of seem to be workarounds and there is nothing that is supported on the platform.
[select id from profile where name = 'System Administrator']
does not work for non-english users as the profile name is translated.
Identified Workarounds are as follows:
1. Custom Labels using the translation workbench is manual for every language.
2. Custom Settings calling out names is manual for every language.
3. Workflow rule on user record copying the profile name to a custom field is a workaround.
4. Adding the profile name to the profile description and querying that fiels is a workaround.
Anybody run into this issue and have a platform supported solution?
There is another way to get around this without creating new fields.
In a recent implementation we had to refer to profiles and record types dynamically from Apex code. rather than call them directly from Apex code, we created custom settings for each line entry, and use the record ID.
For example your sys admin profile might be called “System Administrator” and have an ID of “1234ABCD“. Then follow these steps:
- Create a customer setting called “Config Settings” and make it of
type list, and give it an object an of “Config_Settings__c“
- Click on” manage” your new “Config Settings” and click on new
- Create a config setting (give it a unique name like “sysAdminRecordID” and give it a text value that is the same as your actual Sys Admin profile ID
- Now you can access the record from your Apex code
This way you avoid issues with translation, and you abstract accessing a record using it’s name. Of course you have to treat this as an environment variable, from one sandbox to another. However the likelihood is that a profile is setup once and not changed again.