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
Chinmaya NewChinmaya New 

How can send email to a queue using email alert ?

I have a queue where thare are 10 members. and I have created a email alert.

how can i send email using email alert to this particualr queue ?
There is no option to select queue in email alert.

Best Answer chosen by Chinmaya New
mukesh guptamukesh gupta
Hi Chinmaya,

it's a salesforce limitation https://trailblazer.salesforce.com/ideaView?id=0873A000000CQDAQA4

but you can achive by apex code:

You can create the list to add all the emails of the members in the queue and then use the Messaging.sendEmail() to send to the list.

Please refer the below sample code:
 
List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>();
for(Default_Case_Queue__c casedefaultSetting : Default_Case_Queue__c.getAll().values())  {
     if(casedefaultSetting.Fleet_PLC__c.equals(equip.Fleet_Owner_PLC__c) && mapQNameWithIds.containsKey(casedefaultSetting.queueName) ){
           Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
           List<String> sendTo = new List<String>();
           sendTo.addAll(emailMap.get(casedefaultSetting.queueName));
           // Assign the addresses for the To and CC lists to the                      mail object.
           mail.setToAddresses(sendTo);


            // Specify the subject line for your email address.
            mail.setSubject('New Case Updated : ' + case.Id);

            // Set to True if you want to BCC yourself on the email.
            mail.setBccSender(false);


          // Specify the text content of the email.
          mail.setPlainTextBody('Your Case: ' + case.Id +' has been updated.');

           mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been updated.<p>'+
     'To view your case <a      href=https://***yourInstance***.salesforce.com/'+case.Id+'>click here.</a>');
                   emailList .add(mail );

                    }
                } 
// Send the email you have created.
Messaging.sendEmail(emailList ); //keep this line out of for loop

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

All Answers

mukesh guptamukesh gupta
Hi Chinmaya,

it's a salesforce limitation https://trailblazer.salesforce.com/ideaView?id=0873A000000CQDAQA4

but you can achive by apex code:

You can create the list to add all the emails of the members in the queue and then use the Messaging.sendEmail() to send to the list.

Please refer the below sample code:
 
List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>();
for(Default_Case_Queue__c casedefaultSetting : Default_Case_Queue__c.getAll().values())  {
     if(casedefaultSetting.Fleet_PLC__c.equals(equip.Fleet_Owner_PLC__c) && mapQNameWithIds.containsKey(casedefaultSetting.queueName) ){
           Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
           List<String> sendTo = new List<String>();
           sendTo.addAll(emailMap.get(casedefaultSetting.queueName));
           // Assign the addresses for the To and CC lists to the                      mail object.
           mail.setToAddresses(sendTo);


            // Specify the subject line for your email address.
            mail.setSubject('New Case Updated : ' + case.Id);

            // Set to True if you want to BCC yourself on the email.
            mail.setBccSender(false);


          // Specify the text content of the email.
          mail.setPlainTextBody('Your Case: ' + case.Id +' has been updated.');

           mail.setHtmlBody('Your case:<b> ' + case.Id +' </b>has been updated.<p>'+
     'To view your case <a      href=https://***yourInstance***.salesforce.com/'+case.Id+'>click here.</a>');
                   emailList .add(mail );

                    }
                } 
// Send the email you have created.
Messaging.sendEmail(emailList ); //keep this line out of for loop

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 
This was selected as the best answer
Chinmaya NewChinmaya New
Hi Mukesh,
Thanks for getting back.

I want to send a customised email when a record is assigned to a queue. How can i do that ?