I have a scenario in which I would like to fire off some Apex functionality when an Attachment is inserted from an EmailMessage object (that is received via Email-to-case).
The trouble is, it does not appear that you can have triggers on standard child relations (such as ContactRole, Attachment) - and if you try to access these children using Triggers on the parent, the children "do not exist yet" because they cannot be inserted until this parent has been and an ID is available.
To this end, we have tried writing an After Insert Trigger on EmailMessage and fire it on an incoming e-mail we know to have attachments, but (whilst the "Has Attachments" flag is set) querying for the respective Attachments returns null. We have also tried using workflow, and flag fields to try to find a point in time (in this single processing request) that the attachments have come into existence, but alas we have had no luck.
Our ultimate goal is actually to re-parent all the attachments coming in on an E-mail, away from the EmailMessage and put them on a custom object (which already exists). We want to stay away from using time-delay/time-based solutions (such as a scheduled job that runs every hour to sweep up e-mails + attachments) as this is part of a responsive support-desk solution, and also there is a lot of other involved functionality. I really, really just want to be able to write:
trigger AttachmentTrigger on Attachment (before insert) {
}
Any input or experience would be most welcome.