function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Wolf Duttlinger 6Wolf Duttlinger 6 

Access custom label translation dynamically in APEX based on language - not VF, not user lang

Hi,

I did search but many answers did either simply use the language of the logged-on user or are relevant to VF where you might state the language in the apx:page tag.

I'm coding an APEX REST API. I.e. a class that is being called from external sites. Part of the data that comes in is a language code.

I need to feed back messages from the class. For these messages I did create custom labels in order to be able to use the translation mechanismn build into SF.

Now - in the program - I need to access the label based upon the language specified as a parameter.

I.E. instead of coding:
if ( lang == 'DE') {
                    returnString = 'Ihre Anfrage wurde weitergeleitet. Wir werden uns in Kürze bei Ihnen melden.';
                } else {
                    returnString = 'Your request has been forwarded. You will hear from us soon.';
                }
I want to have something like:
returnString = Label.hppMsg1( 'DE');
where hppMsg1 has been defined as a custom label.

Any ideas?