CustomObject__History list is always empty in TestMethods - Answers - Salesforce Trailblazer Community
Trailblazer Community
Ask Search:
talal hakamtalal hakam 

CustomObject__History list is always empty in TestMethods

When you create a Custom Object, the object CustomObject__History is automatically created in order to allow the developer to track changes in the Custom Object Records. The problem is that i can't manage to retrieve the
CustomObject__History when i run my test class.
The code is the following:

Help please!

date dt = date.today().addDays(1);                
        CustomObject__c testCustomObject = new Sign_Record__c(Subject__c = 'subject', Status__c = 'ACCEPT_WAIT', Reference__c='HistCont', Expiration_Date__c=dt , Comment__c='Comment');                       
        insert testCustomObject;
                
        CustomObject__c dbtestCustomObject = [SELECT Subject__c, Reference__c, Status__c, Expiration_Date__c, Comment__c FROM Sign_Record__c WHERE Reference__c = 'HistCont'];
       
        
        dbtestCustomObject.Status__c = 'CLOSED';
        update dbtestCustomObject;                    
              
        List<CustomObject__History> listEntityHistory = [SELECT Id, Field, NewValue, OldValue, CreatedDate, CreatedById, CreatedBy.Name FROM Sign_Record__History WHERE Field != 'CallWebservice__c' AND ParentId = :dbtestCustomObject.Id];   
        System.debug('##listEntityHistory TEST: ' + listEntityHistory);           


Johan YuJohan Yu
can you create data and update track fields in testmethods?
Mamoon HajjaMamoon Hajja
Hello Talal, please post your question in the developer.salesforce.com Developer Board.