Notifications
Clear all
Sep 20, 2021 6:47 am
How to get email ids of users or public group members to use as to email ids
1 Reply
Sep 20, 2021 6:50 am
// to get the email ids - from Users List userList = new List(); userList = [SELECT Email FROM User WHERE Name = 'firstname lastname']; List toAddresses = new List(); for (User u : userList) { toAddresses.add(u.Email); } // to get the email ids - from public group List idList = new List(); List toAddresses = new List(); Group gp = [SELECT (SELECT UserOrGroupId FROM GroupMembers) FROM Group WHERE Name = 'My Public Group Name']; for (GroupMember gm : gp.GroupMembers) { idList.add(gm.UserOrGroupId); } List userList = [SELECT Email FROM User WHERE Id IN :idList]; for(User u : userList) { toAddresses.add(u.email); }