function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
The new LearnerThe new Learner 

How to send an email to public groups under queue

HI Experts,

Can anyone help me out, how can i send an email to public group users under a queue based on language. Thanks in advance
Mohamed IthrisMohamed Ithris
Hi,
You Can go ahead with Workflow,ProcessBuilder or Flow to Achieve this Functionality

In WorkFlow Rule :
1.Set the Object -> Set when it will Fire -> put Condition if Language is 'English' and add more Conditons if need.
2.Actions : Choose Email Templete -> Choose Receipent Type : Public Group (Make Sure You Group Email id Should be null otherwise Email Send to the your Group Email not Group of Users).

Thanks
Mohamed Ithris
The new LearnerThe new Learner
HI Mohamed,

I want to send an emails of public group users of an queue based on user language 
Mohamed IthrisMohamed Ithris
Hi,
Then you will go to Customization in the Apex.
1.Send an Email using Apex
2.Write the If conditions and get the Public Group Users from Queue


Send an Email Using Apex :

public class EmailSender {

public void sendMail() {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(getEmailAddresses());
mail.setSubject('This is the subject');
mail.setPlainTextBody('This is the body.');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

}

private List<String> getEmailAddresses() {
List<String> idList = new List<String>();
List<String> mailToAddresses = new List<String>();
Group g = [SELECT (select userOrGroupId from groupMembers) FROM group WHERE name = 'MyPubGroup'];
for (GroupMember gm : g.groupMembers) {
idList.add(gm.userOrGroupId);
}

User[] usr = [SELECT email FROM user WHERE id IN :idList];
for(User u : usr) {
mailToAddresses.add(u.email);
}

return mailToAddresses;

}}

Get the Public Group Users from Queue
You need to Write sub Query or Multiple Query
Here I put MultipleQuery to get the Public group Users of an Queue

All Queries are depened
1.SELECT Id, Name FROM Group where  Type = 'Queue' AND Name = 'Billing Support Queue' - Got your Queue
2.SELECT Id, Name FROM Group where Type = 'Group' Name = 'Billing Support Group' - Got your Group
3.SELECT Id, GroupId FROM GroupMember where GroupId = '00G7F000003YTH***'and Id = '0117F000001j3***'  - Got your Group id from the Queue
 
SV MSV M
Hi Mohamed Ithris, I was trying to send an email from trigger to Public Groups using the above-mentioned approach. I am using a helper class for developing the trigger logic and created another method to get the Public Group emails. But, when the trigger fires I was getting few errors at setToaddresses. Can you help me with how to resolve this...
Piotr MęcnarowskiPiotr Męcnarowski
hello, I have users in public group, I sent a messages to public group. One user did not receive mail .
When I do Test Deliverability I have information- 16 test messages have been sent to this email address.
I open receved mail I I only don't habe this user email adress.

Where is the problem??
Piotr MęcnarowskiPiotr Męcnarowski

hello, I have users in public group, I sent a messages to public group. One user did not receive mail .
When I do Test Deliverability I have information- 16 test messages have been sent to this email address.
I open receved mail I I only don't have this user email adress.

Where is the problem??