Skip to content

Instantly share code, notes, and snippets.

@maybe-joe
Last active April 1, 2016 03:16
Show Gist options
  • Save maybe-joe/354331de677e50ebf39e037096049d3f to your computer and use it in GitHub Desktop.
Save maybe-joe/354331de677e50ebf39e037096049d3f to your computer and use it in GitHub Desktop.
trigger EmailMessageTrigger on EmailMessage(after insert, after update) {
Set<Id> emailsWithAttachments = new Set<Id>();
for(EmailMessage email : Trigger.New){
if (email.Incoming) {
emailsWithAttachments.add(email.Id);
}
}
List<Attachment> attachments = [
select Id
from Attachment
where ParentId in :emailsWithAttachments
];
delete attachments;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment