+ Start a Discussion
Ron-LONRon-LON 

SOQL query unwanted result when user language isn't English

I've learned something today about the following query:

Id sysAdminProfileId = [select Id from Profile where Name = 'System Administrator' limit 1].Id;

When this query is run as part of a trigger fired by a user whose language isn't English, the query doesn't return a result.  So how can I get a consistent result to this query no matter what language the user is set to?  I really don't want to hardcode in profile Id's.  I also don't want to put in a million "or" statements.

Thanks!!
Deepak BalurDeepak Balur
Just curious: If the user's language is not engish, in which language are the picklist values being displayed?
Karthik PKarthik P
Hi Ron,

I am sure this is something which Salesforce needs to look at [ at least to support standard Profiles ]. For the time being, if you don't want to use hardcoded Id values, then I can only think of Custom Labels. Probably you can create a Custom Label to hold the value 'System Administrator' along with other translated values for the same string. For example, you can have 'システム管理者' as the value in Japanese. And then you refer to the System Admin label in the SOQL query as shown below, assuming that the name of the Custom Label is SysAdminName:

Id sysAdminProfileId = [select Id from Profile where Name = :Label.SysAdminName limit 1].Id ;

This way, you would avoid errors like 'System.QueryException: List has no rows for assignment to SObject'.

Hope it helps!

Thanks,
Karthik