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
GauravKumarGauravKumar 

How can I move Email attachment to a Case when Case Email has attachments?

is there cany way we can move Case Email Attachments to Case instaead of the Email via any Trigger?

 

I know when a Case Email is sent, it gets logged into EmailMessage, but my trigger on EmailMessage returns no Attachments, and my trigger on Attachment object does not fire at all, as if when Email attchments are inserted into Attachment it never triggers the attachment trigger.

 

Can anyone help me ... plz.

paul-lmipaul-lmi

Sure.  You'd have a trigger on Task.  Determine if the WhatId of the Task is a Case.  If it is, query the Attachment table based on the Task ID, and if Attachments are found, change the ParentId of each attachment to be the Case ID instead of the Task ID.

GauravKumarGauravKumar

Hi,

 

I have created trigger on Task on after insert. but on Task i did not found attachment list so i am unable to update attachment parentid.

Jonathan GreenJonathan Green
If anyone finds this... 4 years (and 4 days) later. The trigger can to be on Attachment. The logic can be: 

For each attachment in trigger, verify that the parent is an EmailMessage:
if( String.valueOf(attachment.ParentId.getSobjectType()) == 'EmailMessage' )
Then pull your emailmessage records and verify the Email Message belongs to a case:
if( String.valueOf( emails.get(eId).ParentId.getSobjectType() ) == 'Case' )
IF that's the case, then set attachment ParentId to equal the email message ParentId. 

That is: Before insert for each new attachment, if it belongs to an email and that email belongs to a case, update the attachment's ParentId to the caseID.