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 {
    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];

        // -> English when called from Lightning, Finnish otherwise

        // ...

1 Answer 1


This post is a bit old and looks like the issue is fixed since then because toLabel function correctly translates in user language in lightning component.

For reference, this quick sample code below works on a custom object (Favorite__c) related to another one (Property__r) which has recordtypes

Apex controller method

public with sharing class ApexController{
      public static String getRecordTypeLabel() {    
          String result = 'No data found';
           List<Favorite__c> fav = [ SELECT Id, toLabel(Property__r.RecordType.Name)
                                  FROM Favorite__c 
                                  where Property__r.RecordTypeId != null 
                                  limit 1];


           return result;


    doInit: function (component, event, helper) {


    getRecLabel: function (component) {
        var action = component.get('c.getRecordTypeLabel');
        action.setCallback(this, function (actionResult) {
            component.set('v.recType', actionResult.getReturnValue());


<aura:component controller="ApexController">

  <aura:attribute name="recType" type="String"/>
  <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

        <b>Record Type label: {!v.recType}</b> <!-- translates to recordtype label based on user language -->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.