4

I am having an issue with translations for the product categories.

Example controller :

@AuraEnabled
public static List<ProductCategory> getCategoriesTest(){
    return [SELECT toLabel(Name), ParentCategoryId From ProductCategory WHERE ParentCategoryId = 'xxx'];
}

This query works perfectly fine in the developer console and I get the Category Name in the proper language.

But when I call the controller from a lightning web component (I checked that the locale and language of the user were correct in the controller with UserInfo.getLocale() and UserInfo.getLanguage()), I always get the Category Name in english.

Am I doing something wrong or is this an issue with Salesforce ?

Thank you ! Julien

5
  • 1
    What is the API version of your class? Based on this Q&A this was an issue at one point and it may be resolved in a different API version.
    – nbrown
    Jul 6, 2021 at 15:37
  • The controller and the lwc calling it were both API version 50, I upgraded them to 52 but this does not solve the issue
    – munchj
    Jul 7, 2021 at 7:08
  • 1
    ProductCategory seems like a unique object, it has its own metadata type just for translating. It could be that this isn't supported in an AuraEnabled method (in which case, definitely raise a case with Salesforce). If it's not, you may be able to try SOSL or consider referencing the ProductCategoryDataTranslation metadata to get the translation you need.
    – nbrown
    Jul 7, 2021 at 15:35
  • Thank you so much for this @nbrown, I was able to get the translated labels from the ProductCategoryDataTranslation
    – munchj
    Jul 8, 2021 at 8:28
  • @nbrown, can you post as an answer to the post so I can accept it as the answer ?
    – munchj
    Jul 8, 2021 at 8:30

1 Answer 1

1

I would raise this issue to Salesforce to determine if it is a gap in the implementation of the toLabel function (it sounds like it may be).

If toLabel doesn't work in this situation, there is a workaround. ProductCategory metadata, since it's a part of the B2B expansion to Salesforce, operates a bit differently from other objects. Normally toLabel() would only work on picklist values in a SOQL query, but for ProductCategory there is a separate set of metadata to enable translation (ProductCategoryDataTranslation) via Translation Workbench. You should be able to reference ProductCategoryDataTranslation metadata in Apex to get translated values directly as an alternative.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .