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 : trigger.new)
3: {
4: if (f.Body.startsWith('#activity')) {
5: funcoder__Activity__c a = new funcoder__Activity__c (
6: Name = f.Body.replace('#activity','')
7: );
8:
9: insert a;
10: }
11: }
12: }
Now just go and enter a chatter message, for example #activity Developed an activity application in Salesforce.