function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Andries.NeyensAndries.Neyens 

SOQL and User Locale

Something as simple as:

 

[SELECT Id FROM Profile WHERE Name='System Administrator' LIMIT 1]

 

can fail if the language locale of the current running user is different than English.

 

Is there a clean workaround?

Andries.NeyensAndries.Neyens

Maybe dirty, but it does the job (test scenario):

 

User u = [Select ID, LanguageLocaleKey FROM User WHERE Id =: UserInfo.getUserId() LIMIT 1];         
u.LanguageLocaleKey = 'en_US';         
update u;

System.runAs(u) {

           [SELECT Id FROM Profile WHERE Name='System Administrator' LIMIT 1]

}