[SalesForce] Describe/use picklist values in specific language, not the User’s language

This Salesforce org includes English and Italian versions of field labels and picklist value labels. This works find within the UI, and for most purposes. However, we have a custom CSV upload page with a validation step that makes sure the values in picklist fields match the standard values, and the picklist values that are returned by the Apex describe command are in the current User's language. For the sake of standardization, we want the CSVs to always be in English, even if the uploading User is Italian.

This is the code I'm using to retrieve the picklist values, which returns it in the current User's language:

Map<String, Schema.SobjectField> allfieldsmap = Schema.SObjectType.Contact.fields.getMap();
Schema.DescribeFieldResult describedField = allfieldsmap.get('Permanent_Country__c').getDescribe();

set<String> picklistvalues = new set<String>();
for (Schema.Picklistentry entry : describedField.getPicklistValues())
{
    picklistvalues.add(entry.label);
}

For an Italian user this gives me a list of countries in Italian (Italia, Messico, etc) instead of the English names, which means that the CSV being uploaded would need to use the Italian versions.

  • How can I get a list of picklist values in English?
  • How can I map the English version of a picklist value to the value in the user's language and successfully update the Permanent_Country__c field?

Best Answer

You only have to use the getValue method instead getLabel.

change this line :

  picklistvalues.add(entry.label);

by this one:

  picklistvalues.add(entry.getValue());

getValue()

Returns the value of this item in the picklist.

getLabel()

Returns the display name of this item in the picklist.

Sum-up: label returns the translated value and value the defined value in the field.