You need to sign in to do that
Don't have an account?
Jai Suresh
EmailMessages created with Apex not listed under Case
I am trying to create a case and send an email with attachment related to the case.
Both are working fine, but the email is not listed under the respective case, but the attachment is properly listed.
Here is the code:
Both are working fine, but the email is not listed under the respective case, but the attachment is properly listed.
Here is the code:
for (Case cRow: lstcase) { //.... String[] arrSendEmailAdd = new String[]{}; arrSendEmailAdd = toAdd.split(','); Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); email.setToAddresses(arrSendEmailAdd); String mailSubject = 'Your Sterling Membership E Kit-ID - '+cuRow.Name; String mailMessage = ''; email.setSubject(mailSubject); email.setHtmlBody(mailMessage); email.setSaveAsActivity(false); email.setWhatId(cRow.Id); //... //Attachment //.... Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); }
This is an expected behavior. When you send an e-mail through Salesforce standard e-mail page it creates a Task with the e-mail informations and links it with the related object (WhatId). However when you sends using apex it does not happens. One workaround would be reproducing the normal behavior, i.e. (you can change it as you wish):
The method setWhatId of SingleEmailMessage class helps to further ensure that merge fields in the template contain the correct data, it does not links it to the object referenced.
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
All Answers
This is an expected behavior. When you send an e-mail through Salesforce standard e-mail page it creates a Task with the e-mail informations and links it with the related object (WhatId). However when you sends using apex it does not happens. One workaround would be reproducing the normal behavior, i.e. (you can change it as you wish):
The method setWhatId of SingleEmailMessage class helps to further ensure that merge fields in the template contain the correct data, it does not links it to the object referenced.
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.
Have you solved your problem?
Regards.
Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.