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
WrogWrogWrogWrog 

Insert triggers do not seem to fire correctly on the Attachments object

Can anyone confirm whether this is a bug or a misunderstanding.

 

I cannot create workflow rules on the Attachment or Note objects to notify that they have been added/changed. Therefore I have created a trigger to update a field on the parent custom object, so that the field can be used for the workflow rule. My trigger for notes works fine, but the trigger for attachments (almost identical to the Notes trigger) only fires for undates, not for inserts, whether these are before or after insert. I've looked in the debug log and the trigger is not called at all if an attachment is inserted.


I think this must be a bug. Can't think of any logical reason why Attachments would behave differently to Notes. 

 

My code looks like this:

 

trigger Attachment_BeforeInsertUpdate on Attachment (before insert, before update) {	Attachment[] att = Trigger.new;	for (Attachment item : att ){				//Ignore if no PCR linked to CSR			PCR__c[] pcrs = [select Id, attachment_change__c from PCR__c where Id = :item.parentid];		System.assert(pcrs.size() > 0);		for (PCR__c pcr : pcrs) {				pcr.attachment_change__c = System.now();			update pcr;		}	}}

 Any thoughts anyone?

 

Roger England 

WrogWrogWrogWrog
Thanks for confirming I'm not insane. Since we can't address this via conventional help cases, how do we get this fixed?
JakesterJakester

Hi Roger,

 

Thank you sooo much for posting your code - I have been wanting to do something very similar to this and have made a ton of progress thanks to your code. My trigger fires After Update, and it works. However, I need to add one more piece to it which I haven't figured just yet. I only want the trigger to fire if a .jpg or .gif is uploaded. Can you (or anyone) tell me how to add the check? Here's the code so far, which updates the Asset field picklist called Picture_Picklist__c to "Specific Picture" any time an attachment is uploaded:

 

 

trigger ImageAttachedToAsset on Attachment (after insert) { Attachment[] att = Trigger.new; for (Attachment item : att ){ //Ignore if attachment name ends in anything except .jpg and .gif Asset[] a = [select Id, name, picture_type_picklist__c from Asset where Id = :item.parentid]; for (Asset assets : a) { assets.picture_type__c = 'Specific Product'; update assets; } }}

 

 

 

 

 

ron_reedron_reed
This appears to be working in Summer 09 - Can someone else validate this?