+ Start a Discussion
Shannon Andreas 1Shannon Andreas 1 

Help with test class for trigger

Hello!

I have created a trigger that will create a contract when the docusign status = Completed. 

I wrote a test class and am getitng the following error:
Error: Compile Error: Invalid type: dsfs_DocuSign_Status__c at line 19 column 42

I know there will be more as well. Wondering if anyone can help me with the test class?

Trigger:
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 validateCreateContractDocSignComp() 
    {   
       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(
      Name = 'DSX-1000000',
      dsfs__Company__c = o.AccountId,
      dsfs__Opportunity__c = o.Id,
      dsfs__Envelope_Status__c = 'Completed');
    insert dsfs;
       
       Test.StartTest();
            
            List<Contract> lstContr = [select id from contract where Opportunity_Name__c =:o.id];
                 //System.assertNotEquals(1stContr,null);
                 
        Test.StopTest();
       
      }
}

Any help is greatly appreciated! Shannon
Jai ChaturvediJai Chaturvedi

Hi,

I think you are using namespace (dsfs) with the object name. Can you try like this:

DocuSign_Status__c dsfs = new DocuSign_Status__c(Name = 'DSX-1000000);

Shannon Andreas 1Shannon Andreas 1
dsfs_DocuSign_Status__c is the object API name...

I did try to remove it and it still gave a similar error.
David ZhuDavid Zhu
If you look at the trigger closely, you  will see the object name is dsfs__DocuSign_Status__c. 
There are two underscore between s and D.

in line 19 of test case, it is dsfs_DocuSign_Status__c.