How to get email id...
 
Notifications
Clear all

[Solved] How to get email ids of users or public group members in salesforce

2 Posts
1 Users
0 Likes
965 Views
Posts: 205
 CWL
Admin
Issue starter
(@cwl)
Member
Joined: 11 years ago

How to get email ids of users or public group members to use as to email ids

Issue Tags
1 Reply
Posts: 205
 CWL
Admin
Issue starter
(@cwl)
Member
Joined: 11 years ago
        // 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);
        }
Reply
Share: