Quantcast
Viewing all articles
Browse latest Browse all 5

Get ALL TopicId from TopicAssignment Apex SOQL Trigger

I'm working on an apex trigger that posts a new feed item every time someone adds a topic to a knowledge article in content management console. This feed item must be tagged with the topicid of the topicassignment. The console, though, allows me to input multiple topics before "save" occurs.

My script is doing amazing at capturing one topic and posting it. Even so, it seems to ignore all other topics. I'm wondering if there's a way to grab ALL of the topics in my query and how to access them from the query results? What is going wrong in my code that it's ignoring all the other topics as well? Google has run out of assistance.

Here's my code:

trigger NewChatterTopicPost on TopicAssignment (before insert) {        List<TopicAssignment> topAs = [SELECT TopicId, EntityId FROM TopicAssignment];        List<Knowledge__kav> knoList = [SELECT Title, UrlName, KnowledgeArticleId FROM Knowledge__kav];        List<FeedItem> postList = new List<FeedItem>();        for(TopicAssignment ta : Trigger.new) {            for(Knowledge__kav kk: knoList) {                if(ta.EntityId == kk.Id) {                    String knoKaTitle = kk.Title;                    String knoKaURL = kk.UrlName;                    String mytopicId = ta.TopicId;                    String topicName = ta.Topic.Name;                    FeedItem post = new FeedItem();                    post.ParentId = mytopicId;                    post.Body = 'A new article called '+ knoKaTitle +' has been added and can be found here: https://services-softdocs.cs8.force.com/community/s/article/'+ knoKaURL;                    postList.add(post);                }             }        }        insert postList;}

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>