1

Can someone help me with this trigger/test class. I am trying to create a contract when the status of a DocuSign = Completed.

trigger CreateContractDocSignComp on dsfs__DocuSign_Status__c (after insert) {
    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;
      }     
}

Test class -

@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'));
       insert o;

       dsfs__DocuSign_Status__c  dsfs = new dsfs__DocuSign_Status__c(
       dsfs__Company__c = o.AccountId,
       dsfs__Opportunity__c = o.Name,
       dsfs__Envelope_Status__c = 'Completed',
       dsfs__DocuSign_Envelope_ID__c = '1001A123-1234-5678-1D84-F8D44652A382',
       dsfs__Subject__c = 'Document for eSignature');
       insert dsfs;

       Test.StartTest();
       List<Contract> lstContr = [select id from contract where Opportunity_Name__c =:o.id];
       //System.assertNotEquals(1stContr,null);
       Test.StopTest();           
   }
}

Thanks!

Shannon

  • so what is your question? – Novarg Sep 1 '15 at 14:56
  • I am trying to get the test class to 1.) provide full coverage 2.) pass – ShannonSF Sep 1 '15 at 19:43
  • I have some new test coding that passes, however, it is missing something because it is not providing any coverage: – ShannonSF Sep 1 '15 at 19:45
2

You're probably throwing an exception on this line and the Docusign record isn't being inserted - the debug logs would be the best place to look to confirm it:

dsfs__Opportunity__c = o.Name,

which really should be dsfs__Opportunity__c = o.Id, if this is a lookup field to the Opportunity object.

1

Your new Test Code will run and pass but won't cover the trigger at all. Because inside Test.StartTest() you are inserting the Opportunity not the Docusign related object in which the trigger is wrote.

@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'));
   insert o;

   dsfs__DocuSign_Status__c  dsfs = new dsfs__DocuSign_Status__c(
   dsfs__Company__c = o.AccountId,
   dsfs__Opportunity__c = o.ID, // Modified as per Mark Pond answer
   dsfs__Envelope_Status__c = 'Completed',
   dsfs__DocuSign_Envelope_ID__c = '1001A123-1234-5678-1D84-F8D44652A382',
   dsfs__Subject__c = 'Document for eSignature');       

   Test.StartTest();
   insert dsfs; // Moved the insert inside Test.startTest() so that it will be tested
   List<Contract> lstContr = [select id from contract where Opportunity_Name__c =:o.id];
   //System.assertNotEquals(1stContr,null);
   Test.StopTest();           
   }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.