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

Email to Case Attachments are attached to the email in Related Lists Not to the Case

I have setup email to case on my server I have also successfully configured the large attachment processing. The problem that I have is  with the attachments they are not case attachments they are attachments to the email that created the case and can only show up under the related lists on the case.
Is there a way to do any of the following.
1. Modify email-to-case code to make the email attachments case attachment?
2. Have the email-to-case app put the link from the large attachment processing in the case body?
The reason I need to do this is it takes almost 5 clicks of the mouse to finally get to the attachment and all of our cases will have attachments and this makes the process to difficult for support people
Anyone Please Help!
One of our programmers modified the code and was able to have the email2case attachemnt link put in the body of the new case rather then the email history.
It eliminates the 5 clicks and seems to be working really well - If anyone wants the sample code email me at
Josh, if you are still around and have this code, I'd love it. Can you please share?  thanks! Nancy

Josh or Nancy,

If you have this code and are still willing to share, please let me know. We have been trying to find a way to get email attachments on a case into case attachments but your solution accomplishes what we are looking for.

Thank You, jeff


Hi josh,

can you send me the code to that will make the attachments available in the email to be visible in the attachments related list of case object.


Am in a bad need of this. Code.

You ca send it to





Simple solution will be to create a trigger in Attachment object that copies the attachment to the parent record (Case.EmailMessage.Attachment) through the parent lookups. Only drawback is that they we will end up with duplicate attachments.


Hi joshste,


Could you please share that code


Hi Joshste, Nancy, Vishnu

Could you please share that code to
Juergen SchmiedeckeJuergen Schmiedecke

Behaviour before Salesforce Winter 19’ Attachments handled by Email-to-case are stored as Attachments.
New with Winter 19' the setting : “Save Email-to-Case attachments as Salesforce Files” is available.
Needs to be set for following draft solution to add record file sharing for the related case.

trigger triggeronCDL on ContentDocumentLink (before delete, before insert, before update, after delete, after insert, after update) {
    if (Trigger.isAfter) {

        if (Trigger.isInsert) {
            List<ContentDocumentLink> listnewCDL=new List<ContentDocumentLink>();
            Map<id,id> mapCDL = new Map<id,id>();
            Set<String> setEmailIds = new Set<String>(); 
            for (ContentDocumentLink cdl : {
                if (string.valueof( cdl.LinkedEntityId ).substring( 0, 3 ) == '02s') {
            if (!setEmailIds.isEmpty()) {
                for (EmailMessage emailparentcase : [SELECT Id, ParentId FROM EmailMessage WHERE Id in :setEmailIds]) {
                    If (emailparentcase.ParentId != null) {
                        ContentDocumentLink newCDL = new ContentDocumentLink();
                        newCDL.ContentDocumentId = mapCDL.get(emailparentcase.Id);    
                        newCDL.LinkedEntityId = emailparentcase.ParentId ;
                        newCDL.shareType = 'V'; 
                if (!listnewCDL.isEmpty()) { 
                    insert listnewCDL;