Is it possible to completely replicate in a unit test creating an outbound emailmessage record against a Case? By that I mean including the Task creation.
I've tried the below in a test class (and also in execute anonymous) but no related Task was created:
emailMessage outboundOne = new emailMessage(
ParentId = testCase.Id,
Subject = 'First outbound email subject',
TextBody = 'First outbound email textbody',
ToAddress = newContact.Id,
Status = '3',
Incoming = false
);
Maybe this is handled via the EmailAuthor page and/or the URL parameters...which isn't reproducible in a unit test?
Some background: Basically there is a code based Roll up summary field for inbound/outbound email message - it's code based due to complicated logic around what emails to include in the count.
outboundOne
? Assuming yes, you may also need to insert the Task as part of the testmethod mocking.