SHARE
TWEET

Untitled

a guest Jun 19th, 2017 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void sendPaymentEmail (Map<Id, Id> contactIds) {
  2.  
  3.         // Get the relevant template Id
  4.         Id templateId = [SELECT Id, Name FROM EmailTemplate WHERE developername = 'PaymentTemplate'].Id;
  5.  
  6.         // List of emails
  7.         List<Messaging.SingleEmailMessage> paymentEmailsToSend = new List<Messaging.SingleEmailMessage> ();
  8.  
  9.         // Remove nulls from the contactMap
  10.         for (Id cId : contactIds.keySet())
  11.             if (cId == null && contactIds.get (cId) == null)
  12.                 contactIds.remove (cId);
  13.  
  14.  
  15.         // List of emails
  16.         List<Messaging.SingleEmailMessage> messagesToSend = new List<Messaging.SingleEmailMessage> ();
  17.  
  18.         System.debug('#### IDS : ' + contactIds);
  19.  
  20.         // Create a new email for each contact related to the Registration
  21.         for (Id cId : contactIds.keySet()) {
  22.  
  23.             Messaging.SingleEmailMessage mailMessage = new Messaging.SingleEmailMessage ();
  24.             mailMessage.setTargetObjectId (cId);
  25.             mailMessage.setSenderDisplayName ('Sedex Admin');
  26.             mailMessage.setTemplateId (templateId);
  27.             mailMessage.setWhatId (contactIds.get (cId));
  28.  
  29.             messagesToSend.add (mailMessage);
  30.  
  31.         }
  32.  
  33.         System.debug ('#### EMAILS TO SEND : ' + messagesToSend);
  34.  
  35.         Messaging.sendEmail (messagesToSend);
  36.  
  37.     }
RAW Paste Data
Top