Find your content:

Search form

You are here

Combine Custom settings with Custom Labels


Is there a way to combine custom settings with custom labels ? So that the output from a setting value would be a custom label ?

To explain:

In example, we have an international organisation, and say countries are stored as an ISO code. As this is a limited and stable set of data, using custom settings would be the appropriate way to deal with say the full country name. The issue arises when I do not just want to store the English country name, but want to have it translatable, presenting the right translation depending on the user's locale. Now, this is the point where I'd like to integrate custom settings with custom labels.

So that say the custom setting with name 'some iso code' doesn't return the full country name, but Label.Country'some iso code', which is than automatically translated in the right version.

Sounds good right. But as custom settings are fixed to certain types, as far as I've gotten is put the label name in the settings as a string value. And then .. i'm stuck :). No way to cast a string to a Custom label, or have it be interpreted (and translated) as such, or is there ?

I'm aware this can be done in a custom object & apex, I was hoping for a more automated, "cleaner", less resource consuming way, better integrated, configurable way.

Additional clarrification: *The goal is to extend the use of custom labels (translation workbench), by adding a mapping from any data-based value to a custom label.*

While we could do a long matching process in apex, it would be faster & neater if the custom settings mechanism could be used. There are disadvantaged to custom objects, they require soql & apex, while custom settings & custom labels are cached. They too can be used in many other places. Countries were an example, I'd use this mechanism for every variable value that needs to be translatable.

Attribution to: Samuel De Rycke

Possible Suggestion/Solution #1

Sdry, I have wanted to do exactly this ever since Custom Settings came out. The problem, though, is that there is no Apex API for Custom Labels (click the link to vote for the idea for it!), so Custom Labels cannot be dynamically retrieved or requested within Apex. However, it CAN, as of Spring 12, be done in Visualforce, using Dynamic Components.

Here, I think is what you are looking for in Apex (that cannot yet be done):

Custom Settings + Custom Labels IN APEX (**not yet possible**)

// Get the stored Custom Setting record for User Preferences
User_Prefs__c p = User_Prefs__c.getInstance(UserInfo.getUserId());

// Get the stored ISO Code
String isoCode = p.ISO_Code__c;

// Get the running user's language
String languageKey = [
    select LanguageLocaleKey from User 
     where Id = :UserInfo.getUserId() 
     limit 1

// Get the translation of the ISO Code corresponding to this user's language
String translatedCode = System.Label.getLabel('ISOCode_'+isoCode).getTranslation(languageKey);

And here would be an equivalent if you are using Visualforce:

Custom Settings + Custom Labels IN VISUALFORCE (possible right now)

public class Controller {

    public String getStoredISOCode() {
        // Get the stored Custom Setting record for User Preferences,
        // and return the ISO code
        return User_Prefs__c.getInstance(UserInfo.getUserId()).ISO_Code__c;


/* VF PAGE */
<apex:page controller="MyController">

    <b>ISO Code</b>{!storedISOCode}
    <b>Translated</b>{!$Label['ISOCode_' & storedISOCode]}


Attribution to: zachelrath

Possible Suggestion/Solution #2

Is there a reason you aren't using the default translation workbench?

Also it usually works out better to use a custom object to store countries, as you can then use this table in many other places.

Edit: There is a country/state picklist coming out in winter 13. This only covers Leads/Accounts/Contacts at the moment i believe. Though from talks at dreamforce I believe they want to roll it into a university picklist offering.

Attribution to: Michael

Possible Suggestion/Solution #3

Why wouldn't you just use Custom Labels with the Translation workbench. I'm struggling to grasp the value that Custom Settings add here.

If it must be custom settings (assuming List Custom Setting), probably have a field for each translated language.

So example (these are field names) on a Custom Setting called Translation_Local__c

Name -- English Values

Russian__c -- Russian translation

French__c -- French translation

And so on

You could just have a field for each supported labguage

So if you wanted to get the French value for England, you'd say

String userLanguage = // deduce language from User Record

Translation_Local_c.getInstance('England').get(userLanguage + '_c');

Attribution to: techtrekker
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content