I have a trigger on a custom object trigger cTrigger on C__c(after insert, after update)
that works correctly when a new C__c
is created. C__c
also has Chatter posts enabled and I am trying to write a trigger that runs when a new Chatter post is made on any specific C__c
object. Any help is appreciated.
I have searched through the documentation and triggers of this type are not mentioned.
1 Answer
Assuming you want to write trigger on Chatter Posts made on specific records, what you want is to write a trigger on FeedItem object. You can find more on the documentation here.
FeedItem represents an entry in the feed, such as changes in a record feed, including text posts, link posts, and content posts.
The Record Id of the C__c
record where this post is being made will be available in the feed item trigger by accessing the ParentId field. You can process anything further related to the original record once you capture the parent id.
Parent Id of the Feed Item is described in the documentation as:
ID of the object type to which the FeedItem object is related. For example, set this field to a UserId to post to someone’s profile feed, or an AccountId to post to a specific account.
Also refer to the considerations while writing trigger on chatter objects, which can be found at this link.
-
Thank you for your reply! I was able to use the documentation to successfully create the trigger on 'FeedItem'! If I may ask, I have a follow-up question: If I wanted to create a trigger for when someone comments on a created 'C__c' Chatter Post would I still need to use 'FeedItem'?– SubitoMay 7, 2018 at 15:01
-
trigger FeedItemTrigger on FeedItem (after update) { List<FeedAttachment> attachments = [SELECT Id, Title, Type, FeedEntityId FROM FeedAttachment WHERE FeedEntityId IN :Trigger.new ]; for (FeedAttachment attachment : attachments) { System.debug(attachment.Type); } }
How do only get the posts relatedC__c
?