11

I am trying to populate a picklist with my salesforce orgs displayed languages (viewable through setup > Company Settings> Language Settings).

There is a way to access all available languages (specifically User LanguageLocaleKeys):

 Schema.DescribeFieldResult fieldResult = User.LanguageLocaleKey.getDescribe();
 List<Schema.PicklistEntry> picklistValues = fieldResult.getPicklistValues();

However I don't want to display all LanguageLocaleKeys as my org only supports the languages we have set as displayed languages. Additionally, when some users register with the picklist with all available languages and pick a language that is not in the "displayed languages lists", their language locale key shows as a number in their User detail page in salesforce instead of their language (for example nl_BE shows as 22).

Is there any way to filter this list? Or only retrieve the displayed languages?

Thanks!

0
10

Based on the documentation of the User object, if you remove a language from the Displayed Languages, the corresponding PicklistEntry becomes inactive. Based on my experimentation, this appears to hold true.

In API version 47.0 and later, when using the DescribeSObjectResult API to return PicklistEntry values from this picklist, the active value indicates whether the language is in the user's Displayed Languages (true) or the user's Available Languages (false). All other languages aren’t in the returned active value array.

5

I'm really interested in this topic too.

I contacted Salesforce Support with the same question and their answer was:

Support Answer

I tried Adrian's workaround:

Based on the documentation of the User object, if you remove a language from the Displayed Languages, the corresponding PicklistEntry becomes inactive. Based on my experimentation, this appears to hold true.

and this seems to be working. Thank you very much.

UPDATE

Regarding Adrian's workaround. I found out, at least on my developer org, if you try to get the PicklistEntries you can see the right data, but if you try to access it, for some, to me unknown reason, you get a different list back. In this list all PicklistEntries have set their isActive attribute to true.

My solution to this was using our team's library. I found this by accident but it seems to do the trick. Basically what this lib does is to use this function serializeAny(Object o). This returns system.JSON.serializePretty(o).

In case anyone else wants to use this workaround and comes across the same problem.

Greetz

2
  • 1
    I know its no answer, but I thought it might be helpful since its the same question I have and I got some more insight from Salesforce Support. Since I can't put a bounty yet or upvote, I wanted to contribute this way to possibly get more attention. I didn't want to raise the same question again. Sry for any inconvenience. Best regards Feb 10 '20 at 12:24
  • 3
    Hi Kevin - I think this may add some valuable information for the community. Would you mind just rephrasing the post to express it as an answer, i.e., sharing the detail that Salesforce Support has stated that this specific approach is not supported? Thank you!
    – David Reed
    Feb 10 '20 at 14:41
0

Regarding Adrian's workaround. I found out, at least on my developer org, if you try to get the PicklistEntries you can see the right data, but if you try to access it, for some, to me unknown reason, you get a different list back. In this list all PicklistEntries have set their isActive attribute to true.

Regarding this, I found that the API version must be 47.0 or higher to successfully use isActivity() as stated in Adrian's answer. Otherwise all the picklist values will be active even though it is not in the Display Language list. Give this a try if you are still having an issue

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.