Monday 14 September 2015

How to send a email to Queue Members via Apex Code on Ownership Change in Salesforce

            Let's consider the below example, I have created a case from visualforce page. When certain criteria met, then I need to change the ownership to the queue and need to send an email alert to the queue members. 

           Normally queue email won't go to the queue member, when you update the ownership to queue through apex. For this, Use Database.DmlOption and update the ownership by checking emailHeader.triggerUserEmail check box.


  1. Case newCase = new Case();
  2. newCase.Status = 'New';
  3. insert newCase;
  4.  
  5. Group grp = [select Id from Group where Name='Case Student Queue' and Type = 'Queue'];
  6. newCase.OwnerId = grp.Id;
  7.  
  8. Database.DmlOptions options = new Database.DmlOptions();
  9. options.emailHeader.triggerUserEmail = true;
  10. Database.update(newCase, options);


Reference:


No comments:

Post a Comment

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...