EDIT: This problem seems to have been fixed on Salesforce's end. See Shamina's answer below.
The SOQL toLabel
function doesn't work in my @AuraEnabled
method when called from a Lightning component. UserInfo.getLanguage
returns "fi" (for Finnish) but the Record Type Name field that's supposed to be translated is still in English. Calling this method manually in Developer Console's Execute Anonymous window works as expected, i.e. the field is translated to Finnish.
global without sharing class SomeController {
@AuraEnabled
global static List<AnApexClass> getData() {
System.debug(UserInfo.getLanguage()); // -> "fi"
List<CustomObject__c> recs = [
SELECT Id, toLabel(RelatedObject__r.RecordType.Name)
FROM CustomObject__c
WHERE Field__c = :UserInfo.getUserId()
AND RelatedObject__c != null
ORDER BY RelatedObject__r.RecordTypeId, AnotherField__c];
System.debug(recs[0].RelatedObject__r.RecordType.Name);
// -> English when called from Lightning, Finnish otherwise
// ...
}
}