You need to sign in to do that
Don't have an account?
Ailedroc
EmailMessage object and attachments
I am writing some Apex code to implement my own version of Email-to-Case.
Using the API Developer's Guide information about the fields in the EmailMessage standard object, I was able to include the following code for creating a new EmailMessage in my handleInboundEmail method. However, the API documentation does not specify any attachment fields aside from the boolean HasAttachment. Is there a way I can add email.binaryAttachments and email.textAttachments to the new EmailMessage object?
...
// new EmailMessage object to be created
EmailMessage[] newEmail = new EmailMessage[0];
// Lookup case based on the case number
try
{
Case vCase = [Select Id, CaseNumber, ContactId, OwnerId
From Case Where CaseNumber = :myCaseNumber Limit 1];
String ownerIdStr = vCase.OwnerId;
System.debug('Owner ID as a string = ' + OwnerIdStr);
newEmail.add(new EmailMessage(
FromAddress = email.fromAddress,
FromName = email.fromName,
Incoming = true,
MessageDate = System.now(),
ParentId = vCase.Id,
Status = '0',
Subject = email.subject,
TextBody = email.plainTextBody,
ToAddress = email.toAddresses[0]));
// Insert the new EmailMessage into the case
insert newEmail;
}
...
Hi, did you solve this problem?