Salesforce Chatter Triggers

Today I wanted to create an app that would allow me to add my activity so that I can analyse my time at a future date. I started my trusty IDE to start mocking up the idea when I had to step back for a moment and think there must be a simpler way to do this.

I use Salesforce for managing my projects and I usually post chatter messages to myself and others. What if I could post a custom # message that would be intercepted and posted to a custom object.

No problem… I created a custom object called Activity:


Then all you need to do is go to Customize > Chatter > Triggers and add a new trigger on the Feed Item.It’s then a matter of looking for a #activity tag in the feed item body, pulling the entry out and inserting it into my Activity custom object.

   1:  trigger ActivityPost on FeedItem (after insert) {
   2:      for (FeedItem f :
   3:      {
   4:          if (f.Body.startsWith('#activity')) {
   5:              funcoder__Activity__c a = new 
                                 funcoder__Activity__c (
   6:                  Name = f.Body.replace('#activity','')
   7:              );
   9:              insert a;
  10:          }
  11:      }
  12:  }

Now just go and enter a chatter message, for example #activity Developed an activity application in Salesforce.

Spread the love


  1. Jonathan,

    Thank you for your contribution. I have read a lot of your articles.

    I am very new to triggers and got this error when I try to create a trigger on the FeedItem:

    Error: Compile Error: Invalid type: funcoder__Activity__c at line 6 column 32

    Do I need to create something called funcoder__Activity__c before this will work.

    Sorry if this is a painfully obvious question.


    • Hi John

      I created an object called Activity with fields to hold the information. My alias is funcoder in my account but you will find that yours is different, so the object you are building with. Just go to Setup / App Setup / Create / Objects then click on the object you created (mine was Activity). In the details section you will see API Name. That’s the name you need to use in your Apex code.

      All the best


  2. Hi Jonathan,


    Thank you so much for your help.

    It is greatly appreciated!

    May the Force(.com) be with you!!


  3. Hi Jonathan,

    I want to restrict access of few platform License user to all Chatter Feeds, All groups and documents. Do you have any solution.

Leave a Reply to Jonathan Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Copyright FUNCODER 2021
Shale theme by Siteturner