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

Trigger after insert an Attachment

I have a problem: we should fire a trigger after a file was attached to a custom object. Unfortunately the “after insert” and the “before insert” event on the Attachment object doesn’t get fired (but the after delete event does but we don't need that).

Does anybody has an  idea why? It can't be the code, it's just debugoutput. Or any workaroung?

Best Answer chosen by Admin (Salesforce Developers) 
This appears to be working in Summer 09 - Can someone else validate this?

All Answers

I'm also looking for this answer too.  Anyone figured it out?  We need to fire trigger for some automated workflow and it's critical to do it based on the attachment insertion.  It won't fire on either Before or After Insert.  But Delete and Update work

Message Edited by dkorba2k5 on 04-17-2008 05:11 PM
Answer from Salesfroce> We have entered this as a bug in the system.
This is RIDICULOUS.  2 releases since the first logging of this bug (based on the threads I have seen here. perhaps more.) and still no fix. we have several clients that could benefit from this.  what's interesting, is that it seems to work when an attachment is created via the API, but not via the UI.
Can we get an update on this? It's now 2009 and this is still broken.  Will this be delivered in Spring 09?
bad still isn't working in Spring '09 

I inadvertantly added a duplicate to this:


That's because I didn't look far enough back! I'm shocked to find this is a known bug for over a year.


Come on SF this can't be hard to fix, can it?

This appears to be working in Summer 09 - Can someone else validate this?
This was selected as the best answer

Hi Guys,


Kindly tell me where can i write a trigger for attachment.


For account i can goto customize-->Account-->Trigger.


For attachment how can i do that?


Kindly let me know this.




An Insert Trigger on an Attachment does seem to be working now!




For Attachments, Notes, Tasks, Events and other objects of this type you have to use the IDE to create Triggers.




Hi Mike,


Could you please provide the code for this.....


Don't know if you need this or not, but Merry Christmas:



//Trigger to update the Attachment__c checkbox field in Custom Object(Custom_Obj__c) //if it has any attachments.
trigger TriggerName on attachment (after insert) {
	List<Custom_Obj__c> co = [select id, Attachment__c from Custom_Obj__c where id =: Trigger.New[0].ParentId];
		if(co.size()>0) {
			co[0].Attachment__c = true;
			update co;