0

Here is my trigger. It creates a contract when the DocuSign record status is updated to Completed. DocuSign automatically attaches the signed document in the attachments. How can I include a copy of this attachment in my trigger so it will attach to the new Contract? Thanks in advance for your help!! Shannon

trigger CreateContractDocSignComp on dsfs__DocuSign_Status__c (after update)
{
    List<Contract> ctr = new List<Contract>();

      for(dsfs__DocuSign_Status__c dsfs : Trigger.new)
      {
        if(dsfs.dsfs__Envelope_Status__c == 'Completed')
        {
             Contract c = new Contract(Name = dsfs.Name,
             Status = 'Draft',
             Total_Contract_Value__c =dsfs.Total_Contract_Value__c,
             StartDate = dsfs.Contract_Start_Date__c,
             Payment_Status__c = 'Ready to be Invoiced',
             AccountId = dsfs.dsfs__Company__c,
             Opportunity_Name__c = dsfs.dsfs__Opportunity__c);
             ctr.add(c);
         }
      }
      if(ctr.size() > 0)
      {
            System.debug('-ctr------->'+ctr.size());
            insert ctr;
      }     
}
1
  • Where is the attachments now? Is it attached to the Opportunity?
    – Saroj Bera
    Commented Sep 18, 2015 at 18:11

1 Answer 1

1

If your attachments are with Opportunity then you can Query the attachments with Opportunity Id and attach with Contract as below.

ctr.add(c);
// Copy attchments
list<Attachment> attlist = [SELECT Id, Name, Body FROM Attachment WHERE ParentId=:<Opportunity  Id>];
for (Attachment att:attlist) {
    Attachment a = new Attachment(ParentId = c.Id,
        Name = att.name,
        Body = att.body);
        insert a;
 }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .