You need to sign in to do that
Don't have an account?
prakash_sfdc
Lookup Relationship value assigned from test class getting null
Hi,
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();
ob1.Date2__c=Date.today()+2;
insert ob1;
B ob2 = new B();
ob2.A_Value__c=ob1.Id;
insert ob2;
Now, in apex code I am checking the dates from Object A via B as follows:
if(date.today()<=ob2.A_Value__r.Date1__c)
{
// 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.
if(date.today()<=ob2.A_Value__r.Date1__c)
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