You need to sign in to do that
Don't have an account?
Raj R.
How to send email using email template in apex class?
Hi,
I have an email template (templateId = 'xxxxx') that has custom fields which are part of the email tempalte.
I have a trigger when when criteria A,b, and c are met, then an email is supposed to be sent. i am trying to use an email template while sending the email, but I am getting the follow error message below. Any thoughts as to what is causing the issue?
First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.:
My email code logic is:
I have an email template (templateId = 'xxxxx') that has custom fields which are part of the email tempalte.
I have a trigger when when criteria A,b, and c are met, then an email is supposed to be sent. i am trying to use an email template while sending the email, but I am getting the follow error message below. Any thoughts as to what is causing the issue?
First exception on row 0; first error: INVALID_ID_FIELD, WhatId is not available for sending emails to UserIds.:
My email code logic is:
sendTemplatedEmail(Id whatId, Id targetObj, List<String> toAddr, Id templateId) { //create new SingleEmailMessage (i.e. eml) //setToAddress to toAddr //setTemplateId to templateId //setTargetObjectId to targetObject //setWhatId to whatId //setSaveAsACtivity to false sendEmail(...); }
http://www.codespokes.com/2013/08/how-to-send-email-from-apex-code-with.html
http://sfdcsrini.blogspot.com/2014/06/how-to-get-salesforce-org-wide-address.html
http://opfocus.com/blog/sending-emails-in-salesforce-to-non-contacts-using-apex/
http://salesforce.stackexchange.com/questions/5169/whats-the-advantage-of-using-massemailmessage-instead-of-multiple-singleemailme/5174#5174
http://developer.force.com/cookbook/recipe/creating-email-templates-and-automatically-sending-emails
https://developer.salesforce.com/forums/?id=906F00000008zbSIAQ
Please let us know if this will help you
All Answers
http://www.codespokes.com/2013/08/how-to-send-email-from-apex-code-with.html
http://sfdcsrini.blogspot.com/2014/06/how-to-get-salesforce-org-wide-address.html
http://opfocus.com/blog/sending-emails-in-salesforce-to-non-contacts-using-apex/
http://salesforce.stackexchange.com/questions/5169/whats-the-advantage-of-using-massemailmessage-instead-of-multiple-singleemailme/5174#5174
http://developer.force.com/cookbook/recipe/creating-email-templates-and-automatically-sending-emails
https://developer.salesforce.com/forums/?id=906F00000008zbSIAQ
Please let us know if this will help you
I tried the same that you are mentioned above. But I am getting the static content in the email, I have used some merge fields in the template. That fields are not working. Can you please help me?
Thanks,
Vijay
You can try by hardcoding the id of the record whose merge fields are being referenced in the email. ex- mail.setWhatId('id').
You will see the merge fields being populated in the email, if it works you can then make it dynamic.