1

My client is asking for a requirement where they want to see all Case updates of Chatter group member belong to Chatter group.Currently they can see only when users posts to Chatter group.

Lets say chatter group member creates new case,add comments on case etc.They want to see all these updates on their feed(similar to how we see on facebook)

How to achieve this ?

1

I think you will have to write a trigger on the Case object. I could not find any way to do it with workflow.

The idea is to create a trigger on the Case object that checks whether a case was updated through the chatter group member, something like this (I have not tested the code, use it as a guide for your own implementation):

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

    // Collecting a chatter group member Id's (based on the group name)
    Set<Id> chatterGroupUsers = new Set<Id>();      
    try {
        for(CollaborationGroupMember m : [Select MemberId
                                          From CollaborationGroupMember
                                          Where CollaborationGroup.Name = 'TestGroup1']){
            chatterGroupUsers.add(m.MemberId);
        }
    } catch (Exception ex) {
        ///
    }

    // Creating an email body text
    String emailBody = 'The following Cases were updates by the chatter group member: ';

    for (Case c : Trigger.new) {
        if(chatterGroupUsers.contains(c.LastModifiedById)){
            // Add a case number to the email body only if it was updated by the group member
            emailBody += c.Name + '<br/>';
        }
    }

    // Send some email or so... 
}
0

Thank you Sergey Utko.I followed your approach.Here is the final code

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;
   } 

}

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.