+ Start a Discussion

Lookup Relationship value assigned from test class getting null



I have two objects A and B. B has a look up to A.


//Test class code


A ob1 = new A();

ob1.Date1__c= Date.today();


insert ob1;


B ob2 = new B();


insert ob2;



Now, in apex code I am checking the dates from Object A via B as follows:





// Code block



The code inside IF is never covered in test coverage, it is not able to fetch the value of Date1 and hence the condition is not satisfied. I think some assignment issue in test class. Please help.




Bhawani SharmaBhawani Sharma
Before doing this
you will have to query ob2 object te get the latest data like
ob2 = ;Select ob2.A_Value__r.Date1__c from Object where Id =: Ob2.Id';
and then do you comparison