You need to sign in to do that
Don't have an account?
DannyK89
Email Templates
I am having trouble using an email template. The error I get is: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.: []
Here is the code that I use to send the eamil:
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[]{to}; String[] bbcAddress = new String[]{bcc}; if(attachlist != null){ list<Messaging.Emailfileattachment> emailattachlist = new List<Messaging.Emailfileattachment>(); for(Attachment a : attachlist){ Messaging.Emailfileattachment emailattach = new Messaging.Emailfileattachment(); emailattach.setFileName(a.Name); emailattach.setBody(a.Body); emailattachlist.add(emailattach); } mail.setFileAttachments(emailattachlist); } mail.setToAddresses(toAddresses); mail.setBccAddresses(bbcAddress); if(tempid == null){ mail.setPlainTextBody(body); mail.setHtmlBody(body); mail.setSubject(sub); } else{ mail.setTemplateId(tempid); mail.setWhatId(candmap.get(cand).Id); mail.setTargetObjectId(UserInfo.getUserId()); } Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
You can not set a userId in setwhatId in mail.
WhatId :
All Answers
You can not set a userId in setwhatId in mail.
WhatId :
I am using following template which will slecet by trigger, but when mail recieved thenfields that i want to show with relatedto type not come in mail.... please help me thanks in advance.......... all fields present in Event.
<messaging:emailTemplate subject="cbt" recipientType="User" relatedToType="Event">
<messaging:plainTextEmailBody >
Hello,
{!$User.FirstName} {!$User.LastName} committed to call {!relatedTo.Contact_Name__c} at {!relatedTo.StartDateTime}.
This notification has been sent 15 minutes prior to the scheduled time.
The case can be accessed via the following link: https://cs4.salesforce.com/{!relatedTo.Case_Id__c}
Case Subject: {!relatedTo.Case_Subject__c}
Thank you,
SalesForce
</messaging:plainTextEmailBody>
</messaging:emailTemplate>