My Lookup's(MD) related lookup field is coming up as null in testclass. So I have 3 objects, lets Objects X, Y and Z
Z is the detail and Y is the Master.
Y has a lookup to X
In the test class I am inserting all the 3 records. I have a trigger on 'Z', which collects the object X id's to perform validations, I add them in a set:
Set<Id> productIdSet = new Set<Id>();
for(ObjectZ z : zList from trigger){
productIdSet.add(z.Y__r.X__c);
system.debug('>>>'+z.Y__r.X__c);
}
This runs perfectly fine when run in actual context, but when executed via testclass 'z.Y__r.X__c' , always returns null. I have checked the field and object level permissions, they are fine. I do not want to add conditions for runningTest context, query and populate the set, just to bypass the issue. Kindly help. Thank you.