Whenever a case gets created/modified by one of chatter group member,they want to see the all chatter feed related to the case on the chatter group.

For this I wrote a trigger where I was able to add group member as Follower to Case whenever a case gets created/modified by Chatter group member.When I added them as Follower to Case they see can see updates on their Chatter feed but not on the Chatter group feed

But they want to see all the chatter feed on the Chatter Group.

Is it possible to add Chatter Group as Follower to Case ?

Here is the code that I used to add group member as Follower to Case.

trigger AutoFollowGroupMemberCase on Case (after insert, after update) {

    set<Id> chatterGroupUsers = new set<Id>();
    list<Id> chatterGroupUsersList = new list<Id>();
    list<EntitySubscription> esList = new list<EntitySubscription>();
    map<String,Id>esMap = new map<String,Id>();

    try {

        for(CollaborationGroupMember m : [Select MemberId
                                          From CollaborationGroupMember
                                          Where CollaborationGroup.Name = 'MyGroupName']){

    } catch (Exception ex) {


   list<id>cList = new list<Id>();
   for(Case c:Trigger.new){

   list<EntitySubscription> eList = [select Id,ParentId,SubscriberId from EntitySubscription where ParentId in: clist];

   for(EntitySubscription es: eList){
     esMap.put(es.ParentId +'-'+ es.SubscriberId ,es.SubscriberId);

   for(Case c : Trigger.new){


           for(Integer i=0;i< chatterGroupUsersList.size();i++){

            string idString = c.Id + '-' + chatterGroupUsersList[i];

            if(esMap.get(idString) == null){

            EntitySubscription es = new EntitySubscription();
            es.ParentId = c.id;
            es.SubscriberId = chatterGroupUsersList[i];



    insert esList;


Try using CollaborationGroupRecord for this:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.