+ Start a Discussion
DeptonDepton 

Automatically add users to a public group

Hi guys,

 

Does anyone have a sample code to automatically add all NEW users to a specific Public Group?

 

Thank you!:)

Best Answer chosen by Admin (Salesforce Developers) 
sai.sfsai.sf

You'll need to:

 

create a new GroupMember object

set the GroupId to your group id

set the UserOrGroupId to the user id

insert into the database (or store in a list for later insertion if there are a few of them, to avoid governor limit probs).

All Answers

sai.sfsai.sf

You'll need to:

 

create a new GroupMember object

set the GroupId to your group id

set the UserOrGroupId to the user id

insert into the database (or store in a list for later insertion if there are a few of them, to avoid governor limit probs).

This was selected as the best answer
DeptonDepton

Hi sai.sf,

 

Thank you but I have already checked @bob_buzzard answer that you are sending now. My situation is different that the other one.

 

I would like the NEW user to be added to group automatically once I click on save

 

 

 

.

kennedymankennedyman

That's what his description does.

 

Create a trigger for "after insert" of user records, and do the steps he outlined.

DeptonDepton

ok, will try that! thank you!

Steve Kerr 8Steve Kerr 8
I realise this is a late answer.  One option to consider is adding a top-level role to the public group - including subordinates.  So, e.g. if you add your CEO's role, and subordinates, this should cover everyone.