+ Start a Discussion
Praneetha MurakondaPraneetha Murakonda 

How to get sub topic related to selected Topic in apex?

Hi All,

I' creating a question from community. Question can be created  from either Topic or Group. When ever i'm creating question there is an option to add sub topic related to selected Topic. I need to distinguish between primary topic and subtopic. How can i query subtopic related to selected primary topic in apex.

Please let me know if there is any workaround.


rajat Maheshwari 6rajat Maheshwari 6

Hi Praneetha,

Please use below soql query : - 

List<PrimaryTopic> lst_Primary = new List<PrimaryTopic>([Select Id,fields,(Select Id,fields from subTopic__r) from primaryTopic]);

Something as shown in above will be used.

Please let me know, if it works :)

Rajat Maheshwari

Praneetha MurakondaPraneetha Murakonda

Hi rajat,

Thanks for reply. Actually i need subtopic related to Topic (Standard object).

I need to get Topic and SubTopic related to feedItem. I'm getting Topic Id related to FeedItem from TopicAssignment object like below.

List<TopicAssignment> myFeedItemFeedAssignments = [SELECT Id, NetworkId, TopicId, Topic.Name, EntityId
                                                   FROM TopicAssignment
                                                   EntityId IN  : feedItemId];
I will get TopicId but not able to get SubTopics. I didn't find any field on Topic object related to subtopic.  Please suggest if there is any way to get SubTopics related to Topic                                        

Sudipta SamalSudipta Samal
Hi Praneetha, 

Did you get any solution for sub topic ? 

Amardeep ChauhanAmardeep Chauhan
Do we have Soluction for above question ?  I need help on same.