+ Start a Discussion
Eric Anderson 54Eric Anderson 54 

trigger on one child object inserts into different child object

Hi there I have a custom parent object that has a child object. I also allow on the Parent object 'Notes and Attachments' (Notes & Upload files). We need to have a trigger on the 'Attachements' that will fire a trigger that will create an entry on the Child object of the parent. I don't know what needs to be done (if anything) to have the Child object know the id of the parent object. I presume I need to include the Parent ID when I create the entry in the Child object.

Below is the code I have been experimenting with, but I have not been able to get it to work.
trigger Attachement_After_Add_Del on Attachment (after insert) {
    List<Request_Time_Entry__c> entryList = new List<Request_Time_Entry__c>();
    for(Attachment AttachmentObj : Trigger.new){
    Request_Time_Entry__c entry = new Request_Time_Entry__c();
      entry.Hours_Worked__c = '00';
      entry.Minutes_Worked__c = '15';
      entry.NAME = 'Added Attachment';
      entry.Date_Worked__C = system.Today();
      // I don't know if what I need in the following line is correct. I Don't seem to get any
      // entries created on the child object when I run this code. Or, am I using the wrong 
     // form of 'Trigger' for an 'Attachement'. 
      entry.Related_Object__c = AttachmentObj.ParentId;
      insert entryList;
Any assistance would be greatly appreciated.


Eric Anderson
v varaprasadv varaprasad
Hi Eric,

entry.Related_Object__c = AttachmentObj.ParentId;
use below instead of above line
entry.Related_Object__c = AttachmentObj.id;

Hope this helps you.

Eric Anderson 54Eric Anderson 54

I've inserted some system.debug statements in this trigger as well as one that is working off of a child object. I am seeing the log entries for the trigger firing off of the Child object just fine. However, I am not seeing any log entries for the trigger that is based off of the Attachement Salesforce system object. Is there something i need to change that allows triggers on the "Attachment' object to fire?