Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardvanhook/5263178 to your computer and use it in GitHub Desktop.
Save richardvanhook/5263178 to your computer and use it in GitHub Desktop.
Set Notification Frequency for all members of a Chatter Group
final String NEW_FREQ_FOR_ALL_GROUP_MEMBERS = 'P'; //P=>On each post, D=>Daily, W=>Weekly, N=>Never
final String GROUP_ID = 'CHANGE_ME'; //select id,name from CollaborationGroup
final List<CollaborationGroupMember> members = [
select id, NotificationFrequency
from CollaborationGroupMember
where CollaborationGroupID = :GROUP_ID
and NotificationFrequency != :NEW_FREQ_FOR_ALL_GROUP_MEMBERS
];
if(members != null && members.size() > 0){
for (CollaborationGroupMember member : members) {
member.NotificationFrequency = NEW_FREQ_FOR_ALL_GROUP_MEMBERS;
}
update members;
}
@NirmalaBS85
Copy link

Hi,
Please guide me to write the similar code in Batch class.
Requirement is "Need to override the Notification Frequency of all members of the given Chatter Group "
Details:
Digest_Group__c is a custom object with 2 fields "Name" and "Notification_Frequency__c"
Group ID ='0F9K00000004M86KAE'

Here is my code:

global class batchFrequencyUpdate implements Database.Batchable {
global Database.QueryLocator start(Database.BatchableContext BC) {
String g= '0F9K00000004M86KAE';
String members='select id,MemberId,NotificationFrequency from CollaborationGroupMember where CollaborationGroupID = :g';
return Database.getQueryLocator(members);
}

global void execute(Database.BatchableContext BC, List<CollaborationGroupMember> scope) {    
    List<CollaborationGroupMember> members =new List<CollaborationGroupMember>();
    Digest_Group__c nFreq =new Digest_Group__c();
    nFreq = [SELECT Id,Name,Notification_Frequency__c from Digest_Group__c limit 1];
    if(scope != null && scope.size() > 0){        
    for (CollaborationGroupMember mem : scope) {
       if(mem.CollaborationGroup.Name==nFreq.Name){
        mem.NotificationFrequency = nFreq.Notification_Frequency__c;
        members.add(mem);
      }
      } 
        update members;            
    }        
}   

global void finish(Database.BatchableContext BC) {
}

}

Actual Result: Notification frequecy is not updating.
Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment