Wednesday, January 4, 2017

Salesforce: Auto Add User to Multiple Chatter Groups

Universal Container would like to automate new Salesforce user created auto join certain Chatter groups based on user detail. Example: Finance staff should auto added to Finance group and as the user is based in Asia Pacific, she also need to be added to APAC groups.

Create a custom object "Chatter Group" as mapping for criteria with Group Id. Here are the fields:
  • Name : auto number
  • Group Name : text
  • Group Id : text
  • Active : checkbox
  • Profile : picklist (multi-select)
  • Team : picklist (multi-select)
  • Sub-Team: picklist (multi-select)
Team and Sub-Team is custom fields available in User object.

Example: if the user with Profile = Finance, he/she will be auto added to Finance chatter group. If the user with Team = APAC, he/she will be auto added to APAC chatter group, no matter if the user has been added to other groups earlier.

You may build Process Builder + Flow as this blog sample, but I do feel it is too complicate go with that route because of  Mixed DML error. Using trigger and apex class would be much simpler, you download snapshot of the code from here.

In essence, you just need to insert new record to this object 'CollaborationGroupMember' and populate following 2 fields:
- CollaborationGroupId = Chatter Group Id
- MemberId = User Id

Things that you need consider to be covered in the code:
- When user created
- When user change profile or other criteria, the code should auto add user to new groups
- When deactivated user become active again
- When user deactivated -- there is no need to care for this, Salesforce will auto remove users from all groups

No comments:

Post a Comment

Page-level ad