+ Start a Discussion
rohitrrohitr 

Trigger on ContactFeed

Just came to know that Trigger over contact field is not permitted.

Is there any alternative to ContactFeed trigger. I want the latest contactfeed to appear on the corresponding contact record.

Puja_mfsiPuja_mfsi

Hi,

You can't write trigger on ContactFeed but you can write trigger on FeedItem. 

And iterate the each feedItem record and check if the feed Item is on contact via parentId ,if yes do your code.

 

trigger contactFeed on FeedItem (after insert) {
       //Find Out the Contact keyPrefix.

       String conKeyPrefix = Contact.sObjectType.getDescribe().getKeyPrefix();
        // Iterate feed item over the loop
        for (FeedItem f: trigger.new) {

                  //Get the parent Id of feedItem
                  String parentid = f.Parentid;

                  // Check if the parentid prefix equals to Contact it means this is the contactFeed item and do your Work.
                  if( parentid.substring(0,3) == conKeyPrefix ) {

                            //Store the Id as per your requirement.
                  }
         }
}

 

 

Please let me know if you have any query on same.And if this post is helpful please give KUDOS  by click on star at left.