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
Shannon Andreas 1Shannon Andreas 1 

Trigger that copies attachment from custom object record to contract record

Hello Friends,

I need assistance writing a trigger that will allow me to copy an attachment from a DocuSign object to a contract.

Just some background...

I have a trigger that creates a contract when DocuSign_Status (object) = Completed. The DocuSign workflow adds the attachment to the already created DocuSign_Status record when signing is completed; which fires the trigger to create the contract. Unfortunately, the trigger does not include copying of the attachment. 

I need to add in copying of the attachment to the current trigger or write a new one, but I need help! I have researched and seen many ways of doing something similar, but not sure it is what I need. I am attaching my trigger below. Any help would be greatly appreciated.

Thanks!  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;
      }     
}

Sanpreet SainiSanpreet Saini
Try to work with attachement object's body and parentid field. 

Below is the syntax that is working in my dev org. 

you can create something like this. 

Sample. 

list<Attachment> at = new list<Attachment>();
for(Attachment a :[select body,parentid  from Attachment limit 1]){

attachment att = new attachment(body=a.body,parentid='00Q9000000cDtBI',name='upload the magic');
system.debug(a.parentid);

insert att;
}

Regards, 
Sanpreet
Shannon Andreas 1Shannon Andreas 1
Sanpreet,

I am somewhat of a novice here. Can you explain "body" and the parentID in this example is naming a particular record right? Why is it specifically named?

Maybe you can just explain how to interpret?

Thanks
Sanpreet SainiSanpreet Saini
Shannon,

The attachment you see on any record is stored under "attachment" object. 

Suppose you want to attach the attachment on contract object object then the "parentid" which is field on attachment will be the contract record id and the "body" field will be of base64. which contains the attachment in base64 format.

In general sense the body will be the attachment in some funky format and the parentid is the record id on which you want to attach the attachment. 

HAve a look at the below link. 
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_noteandattachment.htm

Let me chek out it I can tweak your trigger to make it work to pick up the attachment from your dsfs__DocuSign_Status__c object and put it in contract object. 


Regards, 
Sanpreet
Shannon Andreas 1Shannon Andreas 1
Thanks for the explanation Sanpreet! I would appreciate it if you could tweak the trigger to include this code! I am also going to look around the web to see if I can find an example to match your explanation.

Shannon
Sanpreet SainiSanpreet Saini
Shannon, 

I cretaed a similar scenario in my dev org and it is working. 
Please follow the steps and let me know if that works out for you. 

Step 1: create one text field with api name "dsfsid__c" on contract object that will hold the id of the related docusign object (the logic will be there in trigger to hold the id)

Step 2: save your orginal code and try to replace with this code and let me know if it is working. 
 
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,
             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){
\\map to put the value of docusign object as key and the contract object value as values 
testmap.put(con.dsfsid__c, con.id);
}

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);
}
}

insert attach;
	  
	  }


Fyi similar code is working at my end if by some reason this code does not work. Do not hesistate to reach out. 

Please let me know if you need any help and mark this answer as the best answer if it solved your problem.


Best Regards, 
Sanpreet 
sanpreet.sfdc@yahoo.com
Shannon Andreas 1Shannon Andreas 1
Sanpreet,

It does not like this line:

\\map to put the value of docusign object as key and the contract object value as values
testmap.put(con.dsfsid__c, con.id);
}

Error: Error: Compile Error: line 30:0 no viable alternative at character '\' at line 30 column 0
Shannon Andreas 1Shannon Andreas 1
Sanpreet,

I think it was a copy and paste thing. So I reentered everything manually. It saved the new trigger. Now time to test! 

I am probably going to need help with an updated test class as well :)

Here is the test class I have:

@isTest
private class TestCreateContractDocSignCompTrigger 
{
    static testMethod void validateCreateContractDocuSignComp() 
    {   
       Account a = new Account(
       Name = 'Test Account');
    insert a;

       Opportunity o = new Opportunity(
       Name = 'Test Opp',
       Ready_for_Contract__c = true,
       CloseDate = System.Today(),
       AccountId = a.Id,
       StageName = 'Signed / Closed Sale',
       Amount = decimal.valueof('6995'));
        
    Test.StartTest(); 
    
    insert o;
    
       dsfs__DocuSign_Status__c  dsfs = new dsfs__DocuSign_Status__c();
       dsfs.dsfs__Company__c = o.AccountId;
       dsfs.dsfs__Opportunity__c = o.Id;
       
       dsfs.dsfs__DocuSign_Envelope_ID__c = '1001A123-1234-5678-1D84-F8D44652A382';
       dsfs.dsfs__Subject__c = 'Document for eSignature';
    insert dsfs;
     
      dsfs.dsfs__Envelope_Status__c = 'Completed';
      update dsfs;
                   
            List<Contract> lstContr = [select id from contract where Opportunity_Name__c =:o.id];
                 //System.assertNotEquals(1stContr,null);
                 
        Test.StopTest();
       
      }
}
Shannon Andreas 1Shannon Andreas 1
Sanpreet,

It is not attaching to the contract. 

Just an FYI...the DocuSign Status record is created prior to completion. Not sure if that has any bearing on the code you gave me.

Thanks,

Shannon
Shannon Andreas 1Shannon Andreas 1
Sanpreet,

I found that the dsfsid that is being added to the Contract is adding on letters to the id:

Example 1:

DSFS Id = a0OS00000044oh2
Contract.dsfsid__c = a0OS00000044oh2M

Example 2:

DSFS Id = a0OS00000044ogs
Contract.dsfsid__c = a0OS00000044ogsMAA

Is it becasue I am using the same oppty and quote to test?
Shannon Andreas 1Shannon Andreas 1
i tried reducing the length of the text field to show the right number of characters, but that has done nothing.
Shannon Andreas 1Shannon Andreas 1
Maybe the DocuSign Status object only uses 15-character id and the field I am using uses 18?
Sanpreet SainiSanpreet Saini
Hi Shannon,

Can you try to put the line in the code and check in debug log if you are getting anything. 

system.debug([select id,parentid,body,name from attachment where parentid in : testmap.keyset()]);

 
Shannon Andreas 1Shannon Andreas 1
Sanpreet,

Where should it go in the code?
Shannon Andreas 1Shannon Andreas 1
Hi Sanpreet,

Just wondering if you are still able to assist? If not, I will repost to forum.

Thanks again for your help!

Shannon
Sanpreet SainiSanpreet Saini
Apolgies for the Delay Shannon. 

I again cross checked at my end and it is working fine. 

Can you please check that if you have commented out the below line by mistake. 
testmap.put(con.dsfsid__c, con.id);

No worries!

I have placed the debug logs statement in the code. 
Setup the debug log under your name and then reproduce the issue and capture the debug statements. 

Replace the trigger code with this. 
 
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,
             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;
	  
	  }
Share the results about the debug statements. 

Regards, 
Sanpreet
Shannon Andreas 1Shannon Andreas 1
Ha! I am getting the hang of this! I thought the comments had something to do with the problem :)

I will give this a try...again...thank you for sticking with me on this!

Shannon
Shannon Andreas 1Shannon Andreas 1
Sanpreet,

The debug is pretty long for this one. 

25.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
11:34:20.146 (146519867)|ENTERING_MANAGED_PKG|dsfs
11:34:20.155 (155733284)|SOQL_EXECUTE_BEGIN|[14]|Aggregations:0|SELECT Id, OrganizationType FROM Organization LIMIT 1
11:34:20.160 (160305378)|SOQL_EXECUTE_END|[14]|Rows:1
11:34:20.271 (271542059)|SOQL_EXECUTE_BEGIN|[32]|Aggregations:0|SELECT id, dsfs__ChatterUpdatesEnabled__c, dsfs__DocuSign_Envelope_ID__c, dsfs__Source_Object__c, dsfs__ChatterEnvSent__c, dsfs__ChatterEnvCompleted__c, dsfs__ChatterEnvDeclined__c, dsfs__ChatterEnvDelivered__c, dsfs__ChatterEnvVoided__c, dsfs__ChatterEnvSentText__c, dsfs__ChatterEnvCompletedText__c, dsfs__ChatterEnvDeclinedText__c, dsfs__ChatterEnvDeliveredText__c, dsfs__ChatterEnvVoidedText__c FROM DocuSign_Envelope__c WHERE DocuSign_Envelope_ID__c IN :tmpVar1
11:34:20.277 (277314520)|SOQL_EXECUTE_END|[32]|Rows:0
11:34:20.279 (279883474)|SOQL_EXECUTE_BEGIN|[242]|Aggregations:0|SELECT dsfs__DocuSign_EnvelopeID__c, dsfs__DocuSign_Signer_Type__c, dsfs__DSER_ContactID__c, dsfs__DocuSign_Signature_Name__c, dsfs__DSER_LeadID__c, dsfs__DSER_UserID__c, dsfs__DSER_CustomId__c, dsfs__DSER_CustomFeatures__c, dsfs__DSER_CustomFeaturesEx__c, dsfs__DSER_CustomName__c, d.Id, dsfs__Routing_Order__c, dsfs__Salesforce_Recipient_Type__c, dsfs__DocuSign_Recipient_Role__c, dsfs__RoleName__c FROM DocuSign_Envelope_Recipient__c d WHERE DocuSign_EnvelopeID__c IN :tmpVar1 ORDER BY d.Routing_Order__c ASC NULLS FIRST
11:34:20.286 (286220549)|SOQL_EXECUTE_END|[242]|Rows:0
11:34:20.287 (287753713)|SOQL_EXECUTE_BEGIN|[189]|Aggregations:0|SELECT dsfs__Attachment_NameEx__c, dsfs__Document_Name__c, dsfs__DocuSign_EnvelopeID__c FROM DocuSign_Envelope_Document__c WHERE DocuSign_EnvelopeID__c IN :tmpVar1
11:34:20.290 (290431890)|SOQL_EXECUTE_END|[189]|Rows:0
11:34:20.297 (297599356)|EXECUTION_STARTED
11:34:20.297 (297606788)|CODE_UNIT_STARTED|[EXTERNAL]|01qS0000000DJdo|CreateContractDocSignComp on DocuSign_Status trigger event AfterUpdate for [a0OS0000004Jl7V]
11:34:20.297 (297919598)|SYSTEM_CONSTRUCTOR_ENTRY|[5]|<init>()
11:34:20.297 (297949253)|SYSTEM_CONSTRUCTOR_EXIT|[5]|<init>()
11:34:20.297 (297994889)|SYSTEM_CONSTRUCTOR_ENTRY|[6]|<init>()
11:34:20.298 (298011878)|SYSTEM_CONSTRUCTOR_EXIT|[6]|<init>()
11:34:20.298 (298040754)|SYSTEM_METHOD_ENTRY|[8]|List<dsfs__DocuSign_Status__c>.iterator()
11:34:20.298 (298061257)|SYSTEM_METHOD_EXIT|[8]|List<dsfs__DocuSign_Status__c>.iterator()
11:34:20.298 (298074310)|SYSTEM_METHOD_ENTRY|[8]|system.ListIterator.hasNext()
11:34:20.298 (298089398)|SYSTEM_METHOD_EXIT|[8]|system.ListIterator.hasNext()
11:34:20.307 (307135917)|SYSTEM_METHOD_ENTRY|[15]|Integer.valueOf(Object)
11:34:20.307 (307182284)|SYSTEM_METHOD_EXIT|[15]|Integer.valueOf(Object)
11:34:20.307 (307710312)|SYSTEM_METHOD_ENTRY|[20]|List<Contract>.add(Object)
11:34:20.307 (307739819)|SYSTEM_METHOD_EXIT|[20]|List<Contract>.add(Object)
11:34:20.307 (307751120)|SYSTEM_METHOD_ENTRY|[8]|system.ListIterator.hasNext()
11:34:20.307 (307763939)|SYSTEM_METHOD_EXIT|[8]|system.ListIterator.hasNext()
11:34:20.307 (307781526)|SYSTEM_METHOD_ENTRY|[23]|List<Contract>.size()
11:34:20.307 (307798445)|SYSTEM_METHOD_EXIT|[23]|List<Contract>.size()
11:34:20.307 (307817574)|SYSTEM_METHOD_ENTRY|[25]|List<Contract>.size()
11:34:20.307 (307831524)|SYSTEM_METHOD_EXIT|[25]|List<Contract>.size()
11:34:20.307 (307855976)|SYSTEM_METHOD_ENTRY|[25]|String.valueOf(Object)
11:34:20.307 (307872301)|SYSTEM_METHOD_EXIT|[25]|String.valueOf(Object)
11:34:20.307 (307891344)|SYSTEM_METHOD_ENTRY|[25]|System.debug(ANY)
11:34:20.307 (307904503)|USER_DEBUG|[25]|DEBUG|-ctr------->1
11:34:20.307 (307911558)|SYSTEM_METHOD_EXIT|[25]|System.debug(ANY)
11:34:20.307 (307971805)|DML_BEGIN|[26]|Op:Insert|Type:Contract|Rows:1
11:34:20.784 (784215005)|ENTERING_MANAGED_PKG|hoopla
11:34:20.802 (802867569)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:Contract
11:34:20.892 (892987025)|WF_RULE_EVAL_BEGIN|Workflow
11:34:20.893 (893033020)|WF_CRITERIA_BEGIN|[Contract: 00000695 800S0000000m1GD]|Same Shipping Address|01QS00000001qNy|ON_CREATE_OR_TRIGGERING_UPDATE|0
11:34:20.896 (896346251)|WF_RULE_FILTER|[Contract : Same as Billing Address equals true]
11:34:20.896 (896370200)|WF_RULE_EVAL_VALUE|0
11:34:20.896 (896376291)|WF_CRITERIA_END|false
11:34:20.896 (896397421)|WF_CRITERIA_BEGIN|[Contract: 00000695 800S0000000m1GD]|Contract is Active|01Q30000000Rowt|ON_CREATE_OR_TRIGGERING_UPDATE|0
11:34:20.896 (896429301)|WF_RULE_FILTER|[Contract : Status equals Activated]
11:34:20.896 (896455467)|WF_RULE_EVAL_VALUE|Draft
11:34:20.896 (896460560)|WF_CRITERIA_END|false
11:34:20.896 (896478741)|WF_CRITERIA_BEGIN|[Contract: 00000695 800S0000000m1GD]|Ready to be Invoiced|01Q30000000RpxT|ON_CREATE_OR_TRIGGERING_UPDATE|0
11:34:20.896 (896507135)|WF_RULE_FILTER|[Contract : Payment Status equals Ready to be Invoiced]
11:34:20.896 (896526984)|WF_RULE_EVAL_VALUE|6
11:34:20.896 (896531680)|WF_CRITERIA_END|true
11:34:20.961 (961511283)|WF_SPOOL_ACTION_BEGIN|Workflow
11:34:20.961 (961575284)|WF_RULE_INVOCATION|[Contract: 00000695 800S0000000m1GD]
11:34:20.961 (961590258)|WF_EMAIL_ALERT|Id=01W30000000Q6KD|CurrentRule:Ready to be Invoiced (Id=01Q30000000RpxT)
11:34:21.127 (1127129112)|WF_EMAIL_SENT|Template:00X300000023UIC|Recipients:tmurphy=gmh-inc.com@example.com yacosta=iqmediacorp.com@example.com |CcEmails:tmiller@gmh-inc.com 
11:34:21.127 (1127175682)|WF_ACTION| Email Alert: 1;
11:34:21.127 (1127185290)|WF_RULE_EVAL_END
11:34:21.127 (1127980413)|WF_ACTIONS_END| Email Alert: 1;
11:34:21.127 (1127989440)|CODE_UNIT_FINISHED|Workflow:Contract
11:34:21.128 (1128150957)|DML_END|[26]
11:34:21.128 (1128402135)|SYSTEM_METHOD_ENTRY|[29]|List<Contract>.iterator()
11:34:21.128 (1128720309)|SYSTEM_METHOD_EXIT|[29]|List<Contract>.iterator()
11:34:21.128 (1128764192)|SYSTEM_METHOD_ENTRY|[29]|system.ListIterator.hasNext()
11:34:21.128 (1128789705)|SYSTEM_METHOD_EXIT|[29]|system.ListIterator.hasNext()
11:34:21.128 (1128935395)|SYSTEM_METHOD_ENTRY|[30]|Map<Id,Id>.put(Object, Object)
11:34:21.128 (1128990842)|SYSTEM_METHOD_EXIT|[30]|Map<Id,Id>.put(Object, Object)
11:34:21.129 (1129004478)|SYSTEM_METHOD_ENTRY|[29]|system.ListIterator.hasNext()
11:34:21.129 (1129017630)|SYSTEM_METHOD_EXIT|[29]|system.ListIterator.hasNext()
11:34:21.129 (1129042497)|SYSTEM_METHOD_ENTRY|[32]|Map<Id,Id>.size()
11:34:21.129 (1129065562)|SYSTEM_METHOD_EXIT|[32]|Map<Id,Id>.size()
11:34:21.129 (1129092791)|SYSTEM_METHOD_ENTRY|[32]|String.valueOf(Object)
11:34:21.129 (1129109528)|SYSTEM_METHOD_EXIT|[32]|String.valueOf(Object)
11:34:21.129 (1129130753)|SYSTEM_METHOD_ENTRY|[32]|System.debug(ANY)
11:34:21.129 (1129145491)|USER_DEBUG|[32]|DEBUG|Testmap size is 1
11:34:21.129 (1129152436)|SYSTEM_METHOD_EXIT|[32]|System.debug(ANY)
11:34:21.129 (1129192843)|SYSTEM_METHOD_ENTRY|[35]|Map<Id,Id>.keySet()
11:34:21.129 (1129256596)|SYSTEM_METHOD_EXIT|[35]|Map<Id,Id>.keySet()
11:34:21.130 (1130021695)|SOQL_EXECUTE_BEGIN|[34]|Aggregations:0|SELECT id, parentid, body, name FROM attachment WHERE parentid = :tmpVar1
11:34:21.166 (1166650637)|SOQL_EXECUTE_END|[34]|Rows:0
11:34:21.166 (1166780859)|SYSTEM_METHOD_ENTRY|[34]|String.valueOf(Object)
11:34:21.166 (1166839102)|SYSTEM_METHOD_EXIT|[34]|String.valueOf(Object)
11:34:21.166 (1166865796)|SYSTEM_METHOD_ENTRY|[34]|System.debug(ANY)
11:34:21.166 (1166891768)|USER_DEBUG|[34]|DEBUG|query data()
11:34:21.166 (1166906534)|SYSTEM_METHOD_EXIT|[34]|System.debug(ANY)
11:34:21.166 (1166958103)|SYSTEM_METHOD_ENTRY|[36]|Map<Id,Id>.keySet()
11:34:21.167 (1167007137)|SYSTEM_METHOD_EXIT|[36]|Map<Id,Id>.keySet()
11:34:21.167 (1167343897)|SOQL_EXECUTE_BEGIN|[36]|Aggregations:0|SELECT id, parentid, body, name FROM attachment 
11:34:21.178 (1178521347)|SOQL_EXECUTE_END|[36]|Rows:0
11:34:21.178 (1178602491)|SYSTEM_METHOD_ENTRY|[36]|Database.QueryLocator.iterator()
11:34:21.178 (1178766655)|SYSTEM_METHOD_ENTRY|[7]|QueryLocatorIterator.QueryLocatorIterator()
11:34:21.178 (1178780215)|SYSTEM_METHOD_EXIT|[7]|QueryLocatorIterator
11:34:21.178 (1178852030)|SYSTEM_METHOD_EXIT|[36]|Database.QueryLocator.iterator()
11:34:21.178 (1178872920)|SYSTEM_METHOD_ENTRY|[36]|Database.QueryLocatorIterator.hasNext()
11:34:21.178 (1178891952)|SYSTEM_METHOD_EXIT|[36]|Database.QueryLocatorIterator.hasNext()
11:34:21.178 (1178944784)|SYSTEM_METHOD_ENTRY|[43]|String.valueOf(Object)
11:34:21.178 (1178979364)|SYSTEM_METHOD_EXIT|[43]|String.valueOf(Object)
11:34:21.178 (1178995552)|SYSTEM_METHOD_ENTRY|[43]|System.debug(ANY)
11:34:21.179 (1179005086)|USER_DEBUG|[43]|DEBUG|attach is ()
11:34:21.179 (1179012430)|SYSTEM_METHOD_EXIT|[43]|System.debug(ANY)
11:34:21.179 (1179087927)|CUMULATIVE_LIMIT_USAGE
11:34:21.179 (1179087927)|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 2 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 1 out of 150
  Number of DML rows: 1 out of 10000
  Maximum CPU time: 142 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

11:34:21.179 (1179087927)|LIMIT_USAGE_FOR_NS|dsfs|
  Number of SOQL queries: 4 out of 100
  Number of query rows: 1 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

11:34:21.179 (1179087927)|LIMIT_USAGE_FOR_NS|hoopla|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000
  Number of SOSL queries: 0 out of 20
  Number of DML statements: 0 out of 150
  Number of DML rows: 0 out of 10000
  Maximum CPU time: 0 out of 10000
  Maximum heap size: 0 out of 6000000
  Number of callouts: 0 out of 100
  Number of Email Invocations: 0 out of 10
  Number of future calls: 0 out of 50
  Number of queueable jobs added to the queue: 0 out of 50
  Number of Mobile Apex push calls: 0 out of 10

11:34:21.179 (1179087927)|CUMULATIVE_LIMIT_USAGE_END

11:34:21.179 (1179216985)|CODE_UNIT_FINISHED|CreateContractDocSignComp on DocuSign_Status trigger event AfterUpdate for [a0OS0000004Jl7V]
11:34:21.181 (1181179576)|EXECUTION_FINISHED
11:34:21.182 (1182142546)|EXECUTION_STARTED
11:34:21.182 (1182151333)|CODE_UNIT_STARTED|[EXTERNAL]|Workflow:01I30000002XM1b
11:34:21.190 (1190484790)|WF_RULE_EVAL_BEGIN|Workflow
11:34:21.190 (1190525302)|WF_CRITERIA_BEGIN|[DocuSign Status: DSX-0000155 a0OS0000004Jl7V]|Docusign Completed|01Q30000000RtKx|ON_CREATE_OR_TRIGGERING_UPDATE|0
11:34:21.192 (1192477539)|WF_RULE_FILTER|[DocuSign Status : Envelope Status equals Completed]
11:34:21.192 (1192506106)|WF_RULE_EVAL_VALUE|Completed
11:34:21.192 (1192517746)|WF_CRITERIA_END|true
11:34:21.225 (1225183417)|WF_SPOOL_ACTION_BEGIN|Workflow
11:34:21.225 (1225228232)|WF_RULE_INVOCATION|[DocuSign Status: DSX-0000155 a0OS0000004Jl7V]
11:34:21.225 (1225243629)|WF_EMAIL_ALERT|Id=01W30000000Q7jT|CurrentRule:Docusign Completed (Id=01Q30000000RtKx)
11:34:21.282 (1282343359)|WF_EMAIL_SENT|Template:00X3000000244GC|Recipients:jdotson=iqmediacorp.com@example.com krussell=iqmediacorp.com@example.com |CcEmails:
11:34:21.282 (1282382778)|WF_ACTION| Email Alert: 1;
11:34:21.282 (1282387350)|WF_RULE_EVAL_END
11:34:21.282 (1282836664)|WF_ACTIONS_END| Email Alert: 1;
11:34:21.282 (1282844526)|CODE_UNIT_FINISHED|Workflow:01I30000002XM1b
11:34:21.284 (1284138117)|EXECUTION_FINISHED
Sanpreet SainiSanpreet Saini
That's weird!. Are you sure if the attachment is attached to that particular "dsfs__DocuSign_Status__c" record on which you are doing update. 

If yes, then run the soql query in the developer console. 


SELECT id, parentid, body, name FROM attachment where parentid = 'id of the particular dsfs__DocuSign_Status__c record '


Debug logs should be like this 

03:38:32.599 (599650769)|SOQL_EXECUTE_BEGIN|[23]|Aggregations:0|SELECT id, parentid, body, name FROM attachment WHERE parentid = :tmpVar1 03:38:32.631 (631603762)|SOQL_EXECUTE_END|[23]|Rows:1

Let me know the result of the soql query. 
 
Shannon Andreas 1Shannon Andreas 1
Okay. I had to change something back that I changed last week. I reran and same results. 

Earlier in this post, I stated that there was a discrepancy with the DSFS ids? The field was only capturing part of the record id? I went in and extended the amount of characters in the dsfsid field and now it shows the whole id. I did start to read a little about incompatible field types? Is there a chance that this is the problem? The trigger is not matching the attachment to the contract because the field types do not match?
Shannon Andreas 1Shannon Andreas 1
Here is the error:

System.DmlException: Update failed. First exception on row 0 with id a0OS0000004Jl7uMAC; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, CreateContractDocSignComp: execution of AfterUpdate

caused by: System.DmlException: Insert failed. First exception on row 0; first error: STRING_TOO_LONG, dsfsid: data value too large: a0OS0000004Jl7uMAC (max length=15): [dsfsid__c]

Trigger.CreateContractDocSignComp: line 26, column 1: []
Sanpreet SainiSanpreet Saini
The id would be either 15 digit or 18 digit. 
But the first 15 digit should match. 

Regarding the particular soql have you got anything when you ran it in developer console. 


SELECT id, parentid, body, name FROM attachment where parentid = 'id of the particular dsfs__DocuSign_Status__c record '

Regarding the incompatible field types, can you give me more details. 

Regards, 
Sanpreet
Sanpreet SainiSanpreet Saini
The error is coming as I guess you have set field lenght size as 15 but the id is coming as 18 characters. 

Please increase the size to 18 or more for the custom field which is holding the id. 

 
Shannon Andreas 1Shannon Andreas 1
Sanpreet,

The only error I get now is in regard to test class that I have for this trigger (I have not updated it yet with the attachment stuff). 

Another thing I noticed is that even thought I created a relationship between the DSFS object and the Contract, the contract does not write back to the DSFS record. Could this be a problem as well? 

The DS is still not attaching to the Contract record. The id numbers are the same for the first 15, but the Contract record is inputting 18.

Ughhhh....
 When you say run the SOQL query in Dev Console, do you mean just run a test? Or should I be running only a certain line? Sorry for the remedial questions.
Shannon Andreas 1Shannon Andreas 1
If the trigger is creating the contract based on the status of the DS record, shouldn't the contract show up in the related list on the DS record? It is not doing this which states to me that there is no direct connection between what the trigger is creating and the record it is being created from?
Shannon Andreas 1Shannon Andreas 1
There are lookup fields created on each object, so I don't understand why it is not connecting? In the trigger, we state that contract Name = dsfs.Name. The name field on the Contract is a standard text field. The DS Status record Name is an auto number field. When I create a contract the standard way, through a Quote, the Contract Name field comes up as a blank. Shouldn't we be connecting it through the Contract number? or Contract ID?

Maybe we are trying to relate apples to oranges?
Shannon Andreas 1Shannon Andreas 1
Maybe it is connecting the fields because there is a lookup relationship, but not linking them through Ids?
Shannon Andreas 1Shannon Andreas 1
Don't know if this is what you were talking about SOQL Query? I got this:
User-added image
 
Sanpreet SainiSanpreet Saini
Hi Shannon, 

We may be missing something silly. 
Please feel free to reach out on sanpreet.sfdc@yahoo.com 

Regards, 
Sanpreet