Have set of Topics and subtopics in community, I would like to get the subtopic related to particular topic throw apex code.
2 Answers
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'));
}
-
-
I am getting error like
Illegal value for parameter: 'communityId': 09a6F000000tfvzQAA
Commented Dec 17, 2019 at 10:29 -
-
@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)– ytiqCommented 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 Commented Dec 17, 2019 at 13:05
The children become visible when you provide the depth parameter
Integer depth =2;
ConnectApi.ManagedTopicCollection topics = ConnectApi.ManagedTopics.getManagedTopics(communityId,ConnectApi.ManagedTopicType.Navigational,depth);