• Arthor Morgen
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
So this one has me stumped. I have created a Trigger and Apex Class to take the data category tied to a Knowledge Article and map it to a "Case Category" field. The trigger functions correctly by mapping the data category to the case category, however the problem is when I am running it with a user whose language is something other than English and it is putting the translated data category in the case category which is resulting in a lot of junk data.

The reason why it is running my query as the user logged in which results in the return of the translated labels.
This is the return in Japanese
<pre>
11:23:03.252 (252682000)|USER_DEBUG|[41]|DEBUG|DEBUG::: toReturn - (CategoryLevel:[label=All, level=0, name=All, parent=null], CategoryLevel:[label=アカウント/登録/サインイン, level=1, name=Accounts, parent=(already output)], CategoryLevel:[label=アカウントに関する質問, level=2, name=Account_Questions, parent=(already output)], CategoryLevel:[label=アクティベーションに関する問題, level=2, name=Activation, parent=(already output)], CategoryLevel:[label=一度も電子メールを受信していません, level=3, name=Email_Not_Received, parent=(already output)], CategoryLevel:[label=アクティベーションリンクが作動していません, level=3, name=Link_not_working, parent=(already output)], CategoryLevel:[label=ブラウザの問題, level=2, name=Browser1, parent=(already output)], CategoryLevel:[label=一般アカウント, level=2, name=FS_Account, parent=(already output)], CategoryLevel:[label=設定/プロフィール, level=3, name=FS_Account_Maintenance, parent=(already output)], CategoryLevel:[label=設定変更, level=4, name=Change_Settings, parent=(already output)], ...)
</pre>
And here it is in English
<pre>
11:22:06.641 (641524000)|USER_DEBUG|[41]|DEBUG|DEBUG::: toReturn - (CategoryLevel:[label=All, level=0, name=All, parent=null], CategoryLevel:[label=Account/Registration/Sign-in, level=1, name=Accounts, parent=(already output)], CategoryLevel:[label=Account Questions, level=2, name=Account_Questions, parent=(already output)], CategoryLevel:[label=Activation Issues, level=2, name=Activation, parent=(already output)], CategoryLevel:[label=Never Received Email, level=3, name=Email_Not_Received, parent=(already output)], CategoryLevel:[label=Activation link not working, level=3, name=Link_not_working, parent=(already output)], CategoryLevel:[label=Browser Problems, level=2, name=Browser1, parent=(already output)], CategoryLevel:[label=Public Account, level=2, name=FS_Account, parent=(already output)], CategoryLevel:[label=Settings/Profile, level=3, name=FS_Account_Maintenance, parent=(already output)], CategoryLevel:[label=Changing Settings, level=4, name=Change_Settings, parent=(already output)], ...)
</pre>


Below is the Apex Class code that finds the label to put into the case category.

<pre>
private List<CategoryLevel> getCategories(string categAPIName) {
        System.debug('DEBUG::: Category API Name - ' + categAPIName);
  List<CategoryLevel> toReturn = new List<CategoryLevel>();
  DataCategoryGroupSobjectTypePair pair = new DataCategoryGroupSobjectTypePair();
  pair.setSobject('KnowledgeArticleVersion');
  pair.setDataCategoryGroupName(categAPIName);
  for (DataCategory categ : Schema.describeDataCategoryGroupStructures(new Datacategorygroupsobjecttypepair[] { pair }, false)[0].getTopCategories()) {
   CategoryLevel lev1 = new CategoryLevel(0, categ.getLabel(), categ.getName(), null);
   toReturn.add(lev1);
   addSubcategories(lev1, toReturn, categ, 1);
  }
        System.debug('DEBUG::: toReturn - ' + toReturn);
  return toReturn;
}
</pre>