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
Eric Anderson 54Eric Anderson 54 

How to trigger on attachement and insert a record into a child object of a parent object

Hi there,

I have a parent custom object called 'Investigations' which is used for tracking criminal investigations. I have a child object for that parent called 'Time Entry Recap Report' which is used to record when time is put towards an investigation. As part of the 'Investigations' parent object, I have placed the 'Notes and Attachements' list object to the parent object. The user wants an automatic time entry made to the 'Time Entry Recap Report' child object, when ever an 'attachement' is added to the parent object. Basically, the user is trying to reduce rudimentary work that is done the same way every time.  I am trying to figure out how to develop a 'Trigger' that is based on the 'Attachement' process so that does not seem to be placing records in the 'Time reporting' object. Any suggestions on how to fix my code would be greatly appreciated.
 
trigger Attachement_After_Add_Del on Attachment (after insert) {
    List<Time_Entry_Recap_Report__c> entryList = new List<Time_Entry_Recap_Report__c>();
    for(Attachment AttachmentObj : Trigger.new){
    Time_Entry_Recap_Report__c entry = new Time_Entry_Recap_Report__c();
      entry.Hours_Worked__c = '00';
      entry.Minutes_Worked__c = '15';
      entry.NAME = 'Added Attachment';
      entry.Date_Worked__C = system.Today();
     //I've tried several incarnations at the following line of code, and I just can't figure out
     //what it will take to get it to work.       
      entry.Investigation_Time_Entry__c = AttachmentObj.ParentId;
      entryList.add(entry);
     }
     if(entryList.size()>0){
      insert entryList;
     }
}



Thank you very much for your time!

Respectfully,

Eric Anderson