• Graham Dix 8
  • NEWBIE
  • 10 Points
  • Member since 2015
  • Senior Solution Engineer
  • Salesforce.com

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 3
    Likes Given
  • 1
    Questions
  • 0
    Replies
I'm keen to use and advise people to use Process Builder where ever possible as I believe it is easier to maintain than a trigger. However I need advice on where a trigger should always be considered as option number one. Any thoughts or advice gratefully received. 
I´m a System Admin, I´m on lightning version and I´m on Accont object but I can´t edit/create new views.
Hello!

Can someone help me with a trigger? I have it together, but there is an issue with the attachment part. It is not attaching. Here is the trigger:

trigger CreateContractDocSignComp on dsfs__DocuSign_Status__c (after update)
{
    map<id,id> testmap = new map<id,id>();
    
     list <attachment> attach = new list<attachment>();
    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,
             ContractTerm = Integer.valueOf(dsfs.Contract_Term_months2__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,dsfsid__c = dsfs.id);
             ctr.add(c);
        }
      }
      if(ctr.size() > 0)
      {
             System.debug('-ctr------->'+ctr.size());
             insert ctr;
      }
      
        for(contract con : ctr){
         testmap.put(con.dsfsid__c, con.id);
      }
      system.debug('Testmap size is '+testmap.size());
      
      system.debug('query data'+[select id,parentid,body,name from attachment where parentid in :
      testmap.keyset()]);
        for(attachment att : [select id,parentid,body,name from attachment where parentid in : 
      testmap.keyset()]){
      
      if(testmap.containskey(att.parentid)){
      attachment a = new attachment(name=att.name,body=att.body,parentid=testmap.get(att.parentid));
      attach.add(a);
      }
      }
      system.debug('attach is '+attach);
      insert attach;
      
      }

Thanks so much!