1

Have set of Topics and subtopics in community, I would like to get the subtopic related to particular topic throw apex code.

enter image description here

0
2

there is a method for it ConnectApi (reference). I think you need to use that.

ConnectApi.ManagedTopicCollection topics = ConnectApi.ManagedTopics.getManagedTopics(communityId);
for (ConnectApi.ManagedTopic managedTopic : topics.managedTopics) {
    System.debug('###managedTopic.topic.name = ' + ((ConnectApi.Topic)managedTopic.topic).name);

    Set<String> topicNames = new Set<String>();
    for (ConnectApi.ManagedTopic childManagedTopic : managedTopic.children) {
        topicNames.add(((ConnectApi.Topic)childManagedTopic.topic).name + '\n');
    }

    System.debug('### childTopicNames:\n' + String.join(topicNames, '\n'));
}
7
  • @nubie added code that should do the trick) – ytiq Dec 17 '19 at 7:52
  • I am getting error like Illegal value for parameter: 'communityId': 09a6F000000tfvzQAA – nubie Dec 17 '19 at 10:29
  • am trying to pass community id but getting error – nubie Dec 17 '19 at 10:48
  • @nubie Because this is CommunityId and you need to pass there NetworkId. Use SOQL to query your Network and get its' id. Ye, I know it's not really intuitive) – ytiq Dec 17 '19 at 10:55
  • Now i am able to get the topic but , I am not getting the subtopic it's showing 0 child @ytiq – nubie Dec 17 '19 at 13:05

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.