Quantcast
Channel: Add Chatter group as follower to Case - Salesforce Stack Exchange
Viewing all articles
Browse latest Browse all 2

Add Chatter group as follower to Case

$
0
0

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']){            chatterGroupUsers.add(m.MemberId);        }        chatterGroupUsersList.addAll(chatterGroupUsers);    } catch (Exception ex) {    }   list<id>cList = new list<Id>();   for(Case c:Trigger.new){    clist.add(c.id);   }   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){      if(chatterGroupUsers.contains(c.LastModifiedById)){           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];            esList.add(es);            }         }      }  }  if(esList.size()>0){    insert esList;   } }

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images