How to follow the navigational topics available in a community using soql. I want a custom list of topics in the community and a custom button to follow all of them from one single page.
I tried:
To fetch topics :
Class name: LC_onBoardingController
public static ConnectAPI.ManagedTopicCollection getNavigationTopics(){
System.debug('RES***1');
return ConnectAPI.ManagedTopics.getManagedTopics('0DB2200000000WlGAI',ConnectApi.ManagedTopicType.Navigational);//0DB0c0000008On7GAE
}
Map<ID,Object> topicMap = new Map<ID,Object>();
for(ConnectApi.ManagedTopic mtopic : LC_onBoardingController.getNavigationTopics().managedTopics){
topicMap.put(mtopic.topic.id,mtopic.topic)
}
To follow the topics i retreived from the above code I used this :
List<EntitySubscription> listofTopics= new List<EntitySubscription>();
for(String top : topicid){
EntitySubscription Entity = new EntitySubscription();
Entity.SubscriberId = userId;
Entity.parentId = top;
listofTopics.add(Entity);
}
System.debug('RES***1'+listofTopics);
Database.insert(listofTopics,false);
Even after successful DML on going to the Topics page in the community and that particular topic the "Follow" option is enabled and it did not turn to "Following".But in database record was created for the object EntitySubscription with that topic id.Is there some other method to follow it?