+ Start a Discussion
shahid alishahid ali 

Attachment Trigger Not Firing

Hi, I want to auto forward a email in background when it is sent. The email may contain attachment. We know that each attachment in an email is stored as a record of Attachment object. Hence whenever we send any email with attachment, A new record is created of Attachment object, which is happening. But my problem is that, if I write a After Insert trigger on Atatchment object but it is not firing. I can't figure out any plausible explaination for that. Did someone else faced the same issue?

Vinit_KumarVinit_Kumar

How do you it is not getting executed,Did u check debug logs to verify the same.

shahid alishahid ali

Yes, I verified There is no entry in debug log for that. No Log is being generated for the trigger.

Vinit_KumarVinit_Kumar

That means the record was not inserted for Attachment object.You can verify by adding it from UI and see if it executes

shahid alishahid ali

It is Adding. I ran a SOQL on Attachment object. The attachment record is indeed getting inserted. With the parent ID as the ID of the email. But The attachement is not firing when we send a email with attachment.

Vinit_KumarVinit_Kumar

I think u have misunderstood here,sending emails containing Attachments would not invoke Attachment Triggerse  coz that outgoing email attachment will not be inserted in salesforce Attachement object.It will invoke the Trigger when u upload the Fiel from UI.

 

Hope it is clear!!
 

shahid alishahid ali

Hi Vinit, Though I got the solution i needed through a different approach. But I would still like to know how do email attachments are inserted then? just out of curiousity.

Vinit_KumarVinit_Kumar

Salesforce only stores Inbound emails on EmailMessage object and there is no Data for Outgoing emails.

shahid alishahid ali

Ohkay, but then How did SOQL returned the Attachments when I Queried the Attachment object? also it returned the ParentId of attachment same as that outgoing email. How can this happen that Attachment is inserted and After insert trigger is not fired? Does salesforce have a setting to bypass this trigger? this seems to be the only sensible explaination of this strange behaviour!

Vinit_KumarVinit_Kumar

There is no setting of bypassing the Trigger.As per this weird behaviour ,I have not checked it,let me check and then will be in a better situation to answer.

rcravenrcraven

The attachment trigger doesn't seem to work on after insert events (unsure about other events).  Here is a blog post which indicates this was a bug since Winter 10.   I've checked the known issues site and found nothing.

 

http://corycowgill.blogspot.com/2010/12/salesforce-winter-10-attachment-trigger.html

 

Also here is older posts related to this bug

http://boards.developerforce.com/t5/Apex-Code-Development/APEX-Trigger-Not-Firing-on-After-Insert/td-p/81338