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
Dan Glaser 4Dan Glaser 4 

Emailing Attachments from attachment object

I am working on a client which has the following requirement.
  1. An email is attached to a case, this can be from a contact, or an company internal email addrees.
  2. The email contains an attachment, which is saved in attachments and assigned to the case.
  3. The Page layout for the case uses the related list emails and attachments. both the email and attachment show up on the case.
  4. The attachment is reviewed, if it doesn't meet the requirements it gets rejected.
  5. The rejection screen will contain a reject reason and a input fields to change the returning email address. The returning email does not have to be from a contact.
I looked at both apex messaging and calling emailAuthor. 
Apex messaging allowed me to add the attachment to the email. There are a couple serious downside to using this method:
  • Email address may not come from the contacts.
  • Emails are stored in task, not emailmessage. Emailmessage is the related list item in the case. The task is assigned to the contact view.
Emailauthor works fine except the Attachment has to be a document object not a attachment document. 
I thought about copying the attachment to a document, but I don't want two copies of the attachment. I also thought about deleting the document after I sent the email. I think this could be an issue where I would delete the document before salesforce actually sent the email.

I am using an email template. I created one text and one VFP, mostly to see which worked best for this scenerio.

My question is what can I use to send this email with the attachment under these conditions?
 
Dan Glaser 4Dan Glaser 4
I am not sure if this is the best solution, but I created a rejection document to be used to send as an email attachment. Everytime I have to  reject a case attachment the attachment is copied to the rejection document and the email is sent. This seems to work, even with different file types.