+ Start a Discussion
micwamicwa 

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) 
ron_reedron_reed
This appears to be working in Summer 09 - Can someone else validate this?

All Answers

dkorba2k5dkorba2k5
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
micwamicwa
Answer from Salesfroce> We have entered this as a bug in the system.
sabelstromsabelstrom
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.
boratborat
Can we get an update on this? It's now 2009 and this is still broken.  Will this be delivered in Spring 09?
ron_reedron_reed
bad news...it still isn't working in Spring '09 
WrogWrogWrogWrog

I inadvertantly added a duplicate to this: http://community.salesforce.com/sforce/board/message?board.id=apex&message.id=16075&jump=true#M16075

 

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?

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

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.

 

Thanks.

Force2b_MikeForce2b_Mike

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

 

Mike

Force2b_MikeForce2b_Mike

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

 

Mike

SMasterSMaster

Hi Mike,

 

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

clstantonclstanton

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;
		}
}