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
SpunkySpunky 

Need help with insert child item trigger

I have limited (very) programming knowledge and need some help with a trigger so any assistance would be greatly appreciated. 

 

I have 2 custom objects which are part of a managed package(Docusign for salesforce).

How it works is you click "Send" from a Contact and it opens a new window called an envelope [dsfs__DocuSign_Envelope__c] which is a master object with the contact listed as a recipient  [dsfs__DocuSign_Envelope_Recipient__c] which is the child object

 

 

I would like to add an additional standard recipient every time "send" is launched. I did attempt to create a trigger which is listed below but this doesn't work. Please be gentle with your criticism as i'm humiliatated even posting it but here goes;

 

trigger dse on dsfs__DocuSign_Envelope_Recipient__c (after insert) {
    List<dsfs__DocuSign_Envelope_Recipient__c> dser = new List<dsfs__DocuSign_Envelope_Recipient__c>();
    //For each envelope processed by the trigger, add a new  recipient
    for (dsfs__DocuSign_Envelope_Recipient__c newdser: Trigger.New) {
            dser.add(new dsfs__DocuSign_Envelope_Recipient__c(
                        dsfs__DocuSign_Signer_Type__c ='Carbon Copy',
                        dsfs__DSER_ContactID__c = '003Q000000BhWpP'));
        }
}

 

 

 

Jeremy.NottinghJeremy.Nottingh

Well, what you've got seems like it would compile, which is a good start. You take the list of new recipients, and go through them and make a new recipient for each one, that's attached to a specific Contact. Here are my thoughts on your code as it stands:

 

1. You are not using any data from the trigger DSERs to make your new DSER. I would guess you wanted to carry some info from the "original" DSER to the copy.

 

2. You are not inserting any of the new DSERs you create, so after this Trigger is finished, there will be no net effect on your data. I suggest adding a line at the end for "insert dser;"

 

3. This Trigger will cause an infinite loop, since it's going to want to run on the DSERs you create in the loop, and will then want to make copies of those, and then will want to run the Trigger on those copies, and so on. I suggest breaking that loop somehow; maybe by marking these copy recipients in some way, and running a filter on your Trigger to ignore copies.

 

4. The Contact ID you have hardcoded here might work in your sandbox, but it won't work anywhere else. Instead of typing in an ID in your code, try querying for the Contact you need.

 

If you can reply with your requirements for the new dser, and your thoughts on my notes, I'll be happy to help further.

 

Jeremy

SpunkySpunky

Hi Jeremy,

Thanks so much for your feedback. I will update the trigger as you suggested and give it a shot.Will let you know later today if I'm successful