1

When creating a formula field whose value is dependant on the current user's language, I find that I can't reference User.LanguageLocaleKey

For example, when trying to create a link to an image whose content is dependant on the language (as the image contains text) - I would like to be able to do:

  • IMAGE( 'image_url' + $User.LanguageLocaleKey, $Label.ImageLabel )

Similarly, I'd like to create a workflow rule or validation rule that references the language and I find I can't.

Are there any workarounds?

4

Using Labels

You can leverage the fact that labels are automatically translated, even in Formula Fields and workflow rules.

  • Create a Label - "CurrentLanguage"
  • "Translate" that label so that the contents for each entry matches the country code of that langauge.
    • E.g. for English, set Label.CurrentLanguage to en-US
    • for French, set Label.CurrentLanguage to fr
  • Leave the translations alone for any language you want to fall back to your default language.

The label can then be referenced in either Formula Fields or Workflow rules, and is set to the language of the current user as defined by the translations you've set up.

In the above example of a Formula Field referencing an image, the result would be:

  • IMAGE( 'image_url' + $Label.CurrentLanguage, $Label.ImageLabel )

I haven't tested it with Validation Rules, but I see no reason why this wouldn't work.

Using a Custom Field on User

Alternatively, if you don't like the slightly "hacky" nature of using labels in this way (for the record, I do like it, as it gives you the defaulting), you can use a custom field on User...

  • Create a new custom field on User "CurrentLanguage"
  • Write a trigger on both BeforeInsert and BeforeUpdate that sets CurrentLanguage to the value in LanguageLocaleKey
  • Where-ever you would have referenced LangaugeLocaleKey, you can now reference CurrentLanguage.

In the above example of a Formula Field referencing an image, the result would be:

  • IMAGE( 'image_url' + $User.CurrentLanguage__c, $Label.ImageLabel )
  • You should update your question instead of posting it as a new answer. – Raul Feb 10 '17 at 13:00
  • Completely disagree - The "stack" family explicitly offers the capability of posting both a question and an answer in a single post as a way for users to describe a solution to a problem that others may find useful. Updating the question would make it not a question. The official blog backs this up: stackoverflow.blog/2011/07/… – Rob Baillie Feb 10 '17 at 13:04
  • Ah ok. I thought you accidentally posted it as a answer, and in your answer there is no mention at start saying that it is a solution. Also confusion was because you a posted question and its answer almost at same time. – Raul Feb 10 '17 at 13:08
0

For anyone else referencing this solution - The above selected answer works if the user engaging with the content is the one viewing the link. For example, my French Canadian user views a "User URL" field from his own User Record - it will show him the translated value for that Label for his language. BUT, when I as the US EN Admin view his User Record, I will see US_EN for him - I'm seeing his link but with my Translation.

I have verified that User.LocaleSidKey & User.LanguageLocaleKey are both visible in Process Builder, for both Criteria and Actions. So I was able to update a User Field (COLA - Country Lang) on the User Record, so you can now do this without a trigger! Then I can reference that field in my URL Field and everyone will see the same thing regardless of translation :-)

  • 1
    Welcome to SFSE! Something to keep in mind is that the order of answers is not guaranteed to be static. There are options to sort votes by # of votes, by date/time of creation, and by date/time of last activity (creation, edit, comment), and accepted answers may be treated differently. It's not much of an issue here (as there are only two answers right now), but in other situations, it may help to also identify the author of the comment you're referencing. – Derek F Jan 31 at 20:45

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.