I have a picklist field on user object. Now I want to login as get the picklist translated field value when login as a user. So I tried to get the field value using toLabel on the field but it is giving me the picklist field value not the translated field value. Do any one know how to solve this issue.

list<user> userDataList = [SELECT Id, CC_CaseRole__c FROM User WHERE Id =: UserInfo.getUserId()]; 
    string serviceLevel = '';
    system.debug('userDataList '+ userDataList);
    for(User u:userDataList){
        serviceLevel = u.CC_CaseRole__c;  // want to get the translated value of CaseRole. This field is a plicklist.
  • we never translate the value, only the label of the picklist entries... value is what actually saved in the database. is `toLabel(CC_CaseRole__c) , not working? May 14, 2021 at 11:11
  • No it's not working. Yes I was expecting the same we don't need to translate.
    – Anu
    May 14, 2021 at 17:15

1 Answer 1


Your sample code is not using toLabel(). Try the following:

    List<User> userDataList = [
        SELECT Id, toLabel(CC_CaseRole__c) 
          FROM User 
         WHERE Id = :UserInfo.getUserId()
    String serviceLevel = '' + userDataList[0].CC_CaseRole__c; // will contain label

I also simplified the code; UserInfo.getUserId() will always return the running user's Id, Apex won't enforce FLS, and sharing doesn't matter to query the running user; the query will always return a record. I added the '' + to ensure that when the picklist field is null, serviceLevel is the empty string ('') as in your original code.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .