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
AiledrocAiledroc 

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;
}

...

 

 
Message Edited by Ailedroc on 07-22-2009 08:25 AM
Dima SmirnovDima Smirnov

Hi, did you solve this problem?