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
Ross Gilbert 31Ross Gilbert 31 

Trigger to copy attachment from case to custom object on the case


I need a trigger that clones an attachment created on a case to the most recently created custom object on that case.

In other words, let's say I have the case object.  Let's say I have 1 custom object on the case object.  When a case is created or updated with a new attachment on it, I need that attachment to be put on that custom object as well as the attachment.

Use case:

Case is created or updated with an attachment on it.  That attachment should now be automatically added to the custom object "x", not just the case.

I'm working on this but not sure how to get it to work.  I'm thinking the trigger ought to be on the attachment object since that is where the action is happening to trigger everything.

Does anyone have any ideas?
Ishwar ShindeIshwar Shinde
Yes, you are on right track. Write a trigger on attachment, check the parentid's sobject type or check if id starts with '500'. If it saticefy the criteria, fetch the child records associated with Case and clone the attachment on it.

Hope it will help.
Ignacio JimenezIgnacio Jimenez
Hi RossGilbert31, Did you get this working? I am having the same requirement here. Thanks!!