您如何在Apex代码中获得全球选择列表的翻译标签?

问题描述 投票:1回答:1

我有一个使用REST与Salesforce通信的移动应用程序。该应用程序是多语言的,因此正在发送回选择列表值的转换,这与我们在Salesforce中设置转换标签的含义相同,但是当我在选择列表值上执行.getLabel()时(以用户身份登录)。它仍仅返回英文标签版本。那么如何获得标签的翻译版本?

private static String statusMapper(String value){
    System.debug(LoggingLevel.ERROR, 'value = ' + value);
    System.debug(LoggingLevel.ERROR, 'UserInfo.getLanguage(); = ' + UserInfo.getLanguage());
    Schema.DescribeFieldResult statusOptions = Dealer_Inventory_Asset__c.Status__c.getDescribe();
    Map<String, String> labelToValueMap = new Map<String, String>();

    for(Schema.PicklistEntry p : statusOptions.getPicklistValues()){
        System.debug(LoggingLevel.ERROR, 'p.getLabel() = ' + p.getLabel());
        System.debug(LoggingLevel.ERROR, 'p.getValue() = ' + p.getValue());
        labelToValueMap.put(p.getLabel(), p.getValue());
    }

    if(labelToValueMap.containsKey(value)){
        return labelToValueMap.get(value);
    }

    return value;
}

调试日志示例:

18:07:02.0 (165065101)|USER_DEBUG|[413]|ERROR|value = N- No Scan Required fr
18:07:02.0 (165065101)|USER_DEBUG|[414]|ERROR|UserInfo.getLanguage(); = fr
18:07:02.0 (165998322)|USER_DEBUG|[420]|ERROR|p.getLabel() = N- No Scan Required
18:07:02.0 (166101692)|USER_DEBUG|[421]|ERROR|p.getValue() = N- No Scan Required
18:07:02.0 (166190471)|USER_DEBUG|[420]|ERROR|p.getLabel() = S- Scan still needed
18:07:02.0 (166233031)|USER_DEBUG|[421]|ERROR|p.getValue() = S- Scan still needed

翻译表样本:

Translation Table

我觉得我缺少一些基本的东西,我可以通过创建翻译表来解决它,但是我觉得这应该可行。

rest mobile salesforce apex-code multilingual
1个回答
0
投票

该顶点代码按预期工作,API将返回选择列表值的显示名称-可以根据用户区域设置进行翻译。

© www.soinside.com 2019 - 2024. All rights reserved.