+ Start a Discussion

collaboration group member

can any body please help me with,how to add members to a collaboration group using trigger..


Any help would be helpfull..


Thanks in Advance!!!


Sure - its something like this:

trigger addMembers on CollaborationGroup (after insert) {
	//Lets say you want to add everyone with a Dept = Sales to all new groups
	List<user> users=[SELECT Id FROM User WHERE Department='Sales'];
	for (CollaborationGroup g:trigger.new()){
		//Place to store all the members to add
		List<CollaborationGroupMember> gms=new List<CollaborationGroupMember>();
		for (User u:users){
			CollaborationGroupMember gm=new CollaborationGroupMember();
			gm.NotificationFrequency='P';//I forgot what the values are and the API guide isn't loading for me:
		}//for 2
	}//for 1
		insert gms;
	}catch (DMLException e){
		system.debug('The group members werent added properly.  Error: '+e');
}//trigger addMembers

The gist:

1) Get a list of user Id's

2) Figure out the logic of which new groups to add the users to

3) Add them all as new CollaborationGroupMember's