You need to sign in to do that
Don't have an account?
Profile Name changes based on user language?
Hi,
I've written a test that creates a new user using the system admin profile. I select the proflie with this query in my test
Profile p = [SELECT Id,Name FROM Profile WHERE Name='System Administrator'];
The problem is that if the running user is not english the profile name is different. So if I change my language setting and run the same test I get List has no rows for assignment to SObject because the Name is now 'Administrador del sistema'. So my question is, how can I select the standard System Administrator profile in my test in a way that is language independent? I thought I might be able to use the license key but the key is the same for all standard profile licenses.
Thanks for any help!
Idealy you should not use hardcoded value like this as you have to create multi lingual app. So either take it from Custom Label or from any Custom Setting, where you can update it is leanguage change.
Create a label with name System_Administrator_ProfileName and value "System Administrator"
If lang changes use translation workbench and update label as well accordingly.
Makes sense, but System Administrator is a standard salesforce profile. I shouldn't have to create the label since they must already have it. Do you know if the labels already exist and is there a reference somewhere for all the labels salesforce has already created in their backend?
Also I want to point out that some unit test examples given by salesforce use a hard coded profile name
http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods
These should be changed to reflect the proper language independent way of selecting profiles.
Thanks!
Could not find how to transalete default label of this profile , must be some where in Transalation Workbench -> Translate option
tried with different options but could not find , I wil try more on this If I will find will update. But I think the suggestion that I gave to you should work for you.
It would but i'm trying to avoid adding a custom label to store the information that's already in the system or packaging a custom profile just for tests. If it's the only option then I'll do it :)
Thanks for your help!
You can use this query for system admin profile: This way only system admin profile returns on the query.
If need to get Standard User Profile just change PermissionsCustomizeApplication = false.
It had been more than two years since the last answer, and actually it guided me to get another query: I have tried at a clean org and this is the only permission (PrivacyDataAccess) System Administrator have and other don't. At this point, Ordering y Limit are not totally required, but just in case, they are useful.
Additionaly, I have tried to query profiles only with ordering by CreatedDate, and I got System Administrator too, but it better to use another filter.
Then, you will always get System Administrator profile name, no regard your system language.