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 Answers 2

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, 2019 at 7:52
  • I am getting error like Illegal value for parameter: 'communityId': 09a6F000000tfvzQAA Dec 17, 2019 at 10:29
  • am trying to pass community id but getting error Dec 17, 2019 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, 2019 at 10:55
  • Now i am able to get the topic but , I am not getting the subtopic it's showing 0 child @ytiq Dec 17, 2019 at 13:05
1

The children become visible when you provide the depth parameter

Integer depth =2;
ConnectApi.ManagedTopicCollection topics = ConnectApi.ManagedTopics.getManagedTopics(communityId,ConnectApi.ManagedTopicType.Navigational,depth);

You must log in to answer this question.

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