-1

I have created following Template (Visualforce Page Template):GDPR_Subscriber_Notification

If I do send Test and verify Merge fields option,Its working as expected

 <messaging:emailTemplate subject="New Privacy Request -Transaction number" 
recipientType="Contact" relatedToType="GDPRRequestSubscriberStatus__c">

     Dear {!relatedTo.GDPRSubscriber__r.Name},<br/><br/>              

   T***** Id          :   {!relatedTo.GDPRRequest__r.Name}<br/>   
   P****** Id              :   {!relatedTo.GDPRRequest__r.PrimaryId__c}
   D******               :   {!relatedTo.DueDateEOD__c}<br/>       
   R*****          :   {!relatedTo.GDPRRequest__r.RequestType__c}<br/>       
   Created Date            :   {!relatedTo.GDPRRequest__r.CreatedDate}<br/><br/>    

  Regards,<br/>       
  test Team 

In the code Level:

public static void sendingEmailToMultipleSubscriber(List<GDPRSubscriber__c>gdprSubscriberEmailList,string SubId){
    system.debug('gdprSubscriberEmailList@@@'+gdprSubscriberEmailList);
    system.debug('SubId@@'+SubId);
    List<string> toAddress = new List<string>();
    for(GDPRSubscriber__c gdprSub:gdprSubscriberEmailList){
        toAddress.add(gdprSub.Email__c);
    }
    system.debug('toAddress@@@@@@@'+toAddress);
    EmailTemplate et = [SELECT Id,Subject, Body FROM EmailTemplate WHERE DeveloperName ='GDPR_Subscriber_Notification'];
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setTemplateId(et.Id);
    mail.setToAddresses(toAddress);
    mail.setSubject(et.subject);
    mail.setHTMLBody(et.Body);
    mail.setTargetObjectId(SubId);
    // mail.setWhatId(primaryAccount);
    mail.setSaveAsActivity(false);
    mail.setUseSignature(false);
    List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>();
    allmsg.add(mail);
    system.debug('all MSG'+allmsg);
    try {
        Messaging.sendEmail(allmsg,false);
        return;
    } catch (Exception e) {
        System.debug(e.getMessage());
    }

Debug Log:

  gdprSubscriberEmailList@@@(GDPRSubscriber__c:{Name=EADP-CI, Email__c=test1@gmail.com, Alias__c=qa-eadp-ci, Portal_Access__c=true, Active__c=true, Id=a7V0m0000000lKBEAY})

all MSG(Messaging.SingleEmailMessage[getBccAddresses=null;getCcAddresses=null;getCharset=null;getEntityAttachments=null;getFileAttachments=null;getHtmlBody=null;getInReplyTo=null;getOptOutPolicy=SEND;getOrgWideEmailAddressId=null;getPlainTextBody=null;getReferences=null;getTargetObjectId=a7T0m000000DT05EAG;getTemplateId=00X0m000000uhYxEAI;getTemplateName=GDPR Subscriber Notification;getToAddresses=(test1@gmail.com);getWhatId=null;isTreatBodiesAsTemplate=false;isTreatTargetObjectAsRecipient=true;isUserMail=false;])

trying to use the above templates in this mail message but single email message is not triggering.

enter image description here

test1@gmail.com => dummy address. [Added in Question]

2
  • Is the To Address test1@gmail.com valid? – Hemant Jain Feb 18 '20 at 9:44
  • I have added dummy email address for question purpose – Annappa Feb 18 '20 at 9:45
0

Issue got ressoved:

two things:

 Contact cnt = [select id, Email from Contact where email != null limit 1];
 mail.setWhatId(whatID);//object Id
 mail.setTargetObjectId(cnt.id);

Second things:

Need to allow activities on Object Level.Otherwise it shows below error:

SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, SaveAsActivity is not allowed with whatId that is not supported as a task whatId.:
1
  • 1
    This is a great reason why you should never swallow exceptions into the debug log. If you didn't hide the exception, you'd know about this failure right away. – David Reed Feb 18 '20 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.