function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

FeedItem trigger not firing/working

Hello, below is a small trigger code I created on the FeedItem to try and catch when a new FeedItem of type TrackedChange is created for a change on a tracked field in the contact. The idea is that whenever a value changes on a field that is feedtracked on the contact, I need to catch this change and do something with it, in this case woudl be sending an email, but the important thing is to be able to "catch" the event and changed data, the action to take afterwards is not important, could also be just a system.debug() See code below and let me know WHY this is not firing when I make a change to a contact record that has some of its fields tracked:


this is the trigger on the feed item:


trigger FeedItem_Trigger on FeedItem (after insert) {
List<FeedTrackedChange> lstFTC ;
List<FeedItem> feeds, contFeeds;
    //check on insert IF item is for a FeedTrackedChange for Contact (used as POC for Ole Lyngaard)

    	lstFTC = new List<FeedTrackedChange>();
    	feeds = new List<FeedItem>();
    	contFeeds = new List<FeedItem>();
    	//get info needed from
    	 feeds = [Select f.ParentId, f.Id, f.Type, 
                                  (Select FieldName, OldValue, NewValue From FeedTrackedChanges) 
                                  From FeedItem f Where f.Id IN];
    	//for each result check if the parentId is from an contact, if so then get records
        contFeeds = new List<FeedItem>();
        for(FeedItem f:feeds) {
            String fId = f.ParentId;
            if(fId.left(3)== '003') contFeeds.add(f);
        //for each contact feed, get any feedtrackedchanges records (these belong to feeds from tracked fields on contact)
        for(FeedItem f: contFeeds) {
        	//get feedtrackedchanges records:
        	for(FeedTrackedChange ftc:f.FeedTrackedChanges) {
        		FeedTrackedChange newftc = ftc; 
        	for(FeedTrackedChange ftc: lstFTC) {
        		Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        		mail.setSubject('New field tracked item created');
        		List<String> toAddr = new List<String> ();
            	mail.setPlainTextBody ('The following Feed has changed: ' + ftc.FieldName + ', from ' + ftc.OldValue + ' to ' + ftc.NewValue);
            	Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });    

 Again, the important issue here is that this is not generating either an email OR a system debug entry It is as if the trigger is not even firing!  Help please!!


Jia HuJia Hu
TrackedChange can't invoke the Trigger on FeedItem.
In you case, you can try the Trigger on the Contact object.

Yes, I figured that one out after many tries. Really sucks to have such limitations on Chatter API objects, just the fact that you cannot get describe to check which fields are being feedtracked, or that you cannot add triggers on specific Feed objects (acountFeed, custom object feed__c)  really limits everything.


I will take you approach as I think it is the correct way given the possibilities.