I have a custom list button on case that processes the selected case records and sends out an email using SingleEmailMessage. The email sends fine, but I was expecting the outbound email to be related to the case as an EmailMessage record. However, no EmailMessage record is created and related to the case.

I set the whatId to the case: mail.setWhatId(c.Id);

I can create the EmailMessage record in the apex code and set the parentId to the case, but I was hoping that there would be a way to attach the outbound email using SingleEmailMessage as an EmailMessage record on the case. Is that not possible?


There is no direct way of doing this. You need to create a separate record of email message object and need to populate all details to get record in email related list under case.

 EmailMessage emailMsg = new EmailMessage(); // Created a EmailMessage and copy all details.
emailMsg.ParentId = case_temp.Id; //Attach with the case
 emailMsg.MessageDate = system.now(); emailMsg.Status = '0
Insert emailMsg;
| improve this answer | |

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.