+ Start a Discussion
GauravKumarGauravKumar 

Execute trigger on Email Message and Update Attachment ParentId

Can anybody help me how can i do this

When an email  record is created and linked to a Case, then attachment files linked to the email record moved to be part of the Attachments related list for the Case, not the Email.

 

My trigger code is

 

 

trigger emailAttachment on EmailMessage (after insert) {
 
 Attachment[] atts = new Attachment[] {};
 for (Attachment a : [Select ID, ParentID From Attachment Where ParentID IN: trigger.new])
 {
  a.ParentId = trigger.newMap.get(a.ParentID).ParentID;
  atts.add(a);
 }
 if (!atts.isEmpty())
  update atts;
 
}

 

 

this is giviming me no rows.

how can i do this? can anybody help me plz ?

Thanks in Advance

GauravKumarGauravKumar

can anybody guide me how can i do this ?

 

Thanks in Advance

SFDC-vishnuSFDC-vishnu

Please if any response ,it would be helpfull