That's a bit strange... can you confirm the user you are testing this on has the ability to view the parent Sobject / record? Also there's a sharing setting on the field which is the master detail relationship, ie: Employee__c
is set properly. If they are allowed to see the parent record but no modify it you'll have to change the sharing setting to read only.
Lastly, master-detail relationships are always required so there's no way its read only. If this is a standard lookup, make sure it's not limiting your user that you are testing as to only see it as read only.
While you can go up 5 levels in the child to parent direction, you can only go down 1 level in parent to child relationships. See the "Understanding Relationship Query Limitations" section towards the end of the Relationship Queries documentation.
So you will need to use two separate queries. Here is one way to do that (might contain typos):
Map<Id, Child__c> children = new Map<Id, Child__c>([
Select Id, Name, Contact__c, FieldA__c
from Child__c
where Contact__c = :name
]);
Map<Id, List<GrandChild__c>> grandChildren = new Map<Id, List<GrandChild__c>>;
for (GrandChild__c grandChild : [
Select id, Name, Child__c, FieldB__c,
(Select id, Name, GrandChild__c, FieldC__c from GreatGrandChild__r)
from GrandChild__c
where Child__c in :children.keySet()
]) {
List<GrandChild__c> l = grandChildren.get(grandChild.Child__c);
if (l == null) {
l = new List<GrandChild__c>;
grandChildren.put(grandChild.Child__c, l);
}
l.add(grandChild);
}
Set<Id> childIds = new Set<Id>();
for(Child__c child : children.values()) {
List<GrandChild__c> l = grandChildren.get(child.Id);
if (l = null) {
l = new List<GrandChild__c>();
}
// Wrapper now has extra argument and field, the list of grand children with the
// great grand children available in each grand child's GreatGrandChild__r field
wrapList.add(new Wrapper(false, child, l));
}
You will need to check (or just try a few likely values) the name GreatGrandChild__r; normally this would be a plural so it might be GreatGrandChilds__r or GreatGrandChildren__r - that is a choice the person creating the data model makes.
Best Answer
Try using the following controller and vf page Controller:
Vf Page:
This will display contacts of searched account on the page. Let me know if this helps.