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
Gabriel Martins 13Gabriel Martins 13 

Cross-object formula returns null on Apex Test Execution

Dear Comunity, I hope all of you are safe and sound.

Is there any reason for cross-object formula returns null on apex test execution?

My test updated a field, then the System.debug shows the value from the cross-object formula, but it shows null even after querying it: 

That's the piece of the ciode:

 

Test.startTest();
                
        List<CC__c> cardlist = [SELECT Card_Id_CC__c,Card_Last_Modified_Date__c FROM CC__c WHERE Id = :e.Id];
        CC__c cardtest = cardlist[0];
        cardtest.Card_Id_CC__c = 'card12345'; 
        update cardtest;        
        System.debug(cardlist);
        System.debug('Card Last Modified date - CC__c.Card_Last_Modified_Date__c:  ' +cardtest.Card_Last_Modified_Date__c);
              
        
RG__c rglist2 =[Select Card_Last_Modified_Date__c FROM RG__c WHERE ID=:r.id];
        System.debug('This field must be equal to CC__c.Card_Last_Modified_Date__c '+ rglist2.Card_Last_Modified_Date__c);

 

Thank you all

 

 

 

LIKITH OBBINALIKITH OBBINA
Hi,
just to make sure, the test class cannot see the data in org by default unless you use SeeAllData=true.
 
Gabriel Martins 13Gabriel Martins 13

Thanks Likith Obbina,

I'm executing the test code with the standard System Administrator profile and View All Data is set to TRUE on System Permission.