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
Eric Dale 11Eric Dale 11 

Field is null after insert in test

I have a test class which creates an object which includes this field "APXT_CongaSign__ContentDocumentId__c"... this is simply a text field. I then insert the object.
When I do a SOQL query on it, all other field seem to be fine except for this one, which does not show a value.

Here is the test class;
@isTest
    public static void TestBatterySignatureComplete(){
        //Creating the account
        Account account = new Account();
        account.Name = 'Test Account';
        account.SGNS_Contractor_Primary_Email__c = 'test.test@test.ca';
        account.SGNS_Contractor_Secondary_Email__c = 'test.test@test.ca';
        insert account;

        //Creating Battery
        Battery_Energy_Storage_Applications__c batteryApplication = new Battery_Energy_Storage_Applications__c();
        batteryApplication.Contractor__r = account;
        batteryApplication.Contractor__c = account.Id;
        batteryApplication.First_Name__c = 'test';
        batteryApplication.Last_Name__c = 'test';
        batteryApplication.Email__c = 'test.test@test.ca';
        batteryApplication.Stage__c = 'Application Submitted';
        insert batteryApplication;

        //create attachment
        ContentVersion contentVersion = new ContentVersion(
                    Title          = 'Battery Storage Program Participation Agreement',
                    PathOnClient   = 'sign.pdf',
                    VersionData    = Blob.valueOf('Test Content'),
                    IsMajorVersion = true);
            insert contentVersion;

        List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];

        //create ContentDocumentLink  record
        ContentDocumentLink cdl = new ContentDocumentLink();
        cdl.LinkedEntityId = batteryApplication.Id;
        cdl.ContentDocumentId = documents[0].Id;
        cdl.ShareType = 'V';
        cdl.Visibility = 'AllUsers';
        insert cdl;

        //Creating the Conga Transaction record
        APXT_CongaSign__Transaction__c congaTransaction = new APXT_CongaSign__Transaction__c();
        //of these variables are null, the Flow will fail.
        congaTransaction.Parent_a0l__c = batteryApplication.Id;
        congaTransaction.Parent_a0l__r = batteryApplication;
        congaTransaction.APXT_CongaSign__ContentDocumentId__c = documents[0].Id;
        insert congaTransaction;

//AFTER THIS POINT APXT_CongaSign__ContentDocumentId__c  APPEARS NULL AFTER A SOQL QUERY OF THE RECORD.

        //TEST STARTS
        CongaTransaction.APXT_CongaSign__Status__c = 'COMPLETE';
        update CongaTransaction;

        List<Battery_Energy_Storage_Applications__c> updatedBatts = [SELECT Id, Stage__c from Battery_Energy_Storage_Applications__c WHERE Id = :batteryApplication.Id];

        Integer invocations = Limits.getEmailInvocations();
        System.assertEquals('Installation', updatedBatts[0].Stage__c);
        System.assertEquals(1, invocations, 'An email has been sent');
        System.assertEquals(documents.size(), 1);
    }

 
ios tweaksios tweaks
yes test (https://iostweaks.net/)is imp
Mike Jones 103Mike Jones 103
great extracts at (https://kures.co (https://kures.co/kratom-extract/))
Eugene ZhulkovEugene Zhulkov
first fill the APXT_CongaSign__Transaction__c.APXT_CongaSign__OriginalDocumentId__c with the ContentVersion.Id value.
 
after that APXT_CongaSign__Transaction__c.APXT_CongaSign__OriginalDocumentId__c is filled automatically with the ContentDocument.Id value.