function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
insanedukeposseinsanedukeposse 

SingleEmailMessage - saves as Activity, but not as EmailMessage?

I am running a Apex trigger on the Case object that sends an email. The Apex trigger is required as workflow rules to not meet some specific requirements that I have.

 

The snippet below associates the email to the Contact + Case. I can see the activity associated with both objects. However, on the case, the email does not show under the "Emails" related list. (Apex Explorer confirms that an EmailMessage is not created for the outbound email.) Is there a way to force the save of an EmailMessage record?

 

 

system.debug ('contact: ' + Trigger.new[0].ContactId);system.debug ('id : ' + Trigger.new[0].id);mail.setTargetObjectId(Trigger.new[0].ContactId);mail.setWhatId(Trigger.new[0].id);mail.setSaveAsActivity(True);