Print this page

Notify account owners of activities logged against their accounts

Knowledge Article Number 000003788
Resolution

Notifying account owners of activities logged against their accounts can be done by adding a chatter post. Here's example code of a simple trigger to accomplish this. 

trigger accountOwnerChatterUpdateOnTask on Task (after insert) {

//Get the list of accounts where a Task has been added 
List <FeedItem> chatterPostsToAdd = new List <FeedItem>() ;

     

for(Task t : Trigger.new){
        
        //TODO: Change the text of the Body to something meaningful, such as the name of the person who created 
        the task and the due date.
        FeedItem accountPost = new FeedItem();
        accountPost.ParentID = t.accountId ;
        accountPost.Body = 'This is the text that appears in the Account Feed';
        chatterPostsToAdd.add(accountPost);
        
        }

insert chatterPostsToAdd;

}
 

If there was a need for a trigger to be written that would do the same with event, replace task with event in the trigger.

 





promote demote