You need to sign in to do that
Don't have an account?
Noor Fazli
How to find the email addresses of users in a Public group
Hi,
We need to send email to all the members of a public group. How to query emails of all the users in a public group in Apex controller. so far I have done this. Not sure how the object user can be used to get the "email of all users" in a public group.
group g = [SELECT id FROM group WHERE name = 'IT Testers'];
System.debug('g:' + g);
for (GroupMember gm : [Select UserOrGroupId from GroupMember where GroupId =: g.id]){
System.debug('gm.UserOrGroupId:' + gm.UserOrGroupId); }
}
We need to send email to all the members of a public group. How to query emails of all the users in a public group in Apex controller. so far I have done this. Not sure how the object user can be used to get the "email of all users" in a public group.
group g = [SELECT id FROM group WHERE name = 'IT Testers'];
System.debug('g:' + g);
for (GroupMember gm : [Select UserOrGroupId from GroupMember where GroupId =: g.id]){
System.debug('gm.UserOrGroupId:' + gm.UserOrGroupId); }
}
You can simply collect all these UserOrGroupId in a set<String> and then Query on User where Id IN: Set...
This will solve you issue..
Please implement the formula field as I mentioned above and implement the same and let me know if it works for you..
Thanks,
Sandeep
All Answers
You need to first Query on GroupMember and get all userIds...then you need to query on user to get the emails..
But user email is not querable so in this case you need to create a formula field on user which will store the user email address and then that custom field you can query from user ..
Please implement this and let me know if this solves your issue..
P.S. If my answer helps you to solve your problem please mark it as best answer. It will help other to find best answer.
Thanks,
Sandeep
Salesforce Certified Developer
thanks Sandeep for your reply. I'm able to get the UserOrGroupId. I don't seem to understand the hierarchy between GroupMember and User? Which field is used to link them together?
You can simply collect all these UserOrGroupId in a set<String> and then Query on User where Id IN: Set...
This will solve you issue..
Please implement the formula field as I mentioned above and implement the same and let me know if it works for you..
Thanks,
Sandeep
Object was imported from Sandbox
Where is the problem??