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
seallesssealless 

Not a valid child relationship name for entity

I have replaced the standard layout (View detail) for a custom object with a Visualforce page

 

<apex:page standardController="Appointment__c">
    <apex:sectionHeader title="{!$ObjectType.Appointment__c.label}" subtitle="{!Appointment__c.Name}"/>
    <apex:pageBlock title="{!$ObjectType.Appointment__c.label} Detail">
        <apex:pageBlockSection showHeader="false" columns="1">
            <apex:outputField value="{!Appointment__c.Tutor_Name__c}"/>
            <apex:outputField value="{!Appointment__c.Student_Name__c}"/>           
        </apex:pageBlockSection>
     </apex:pageBlock>    
     <apex:relatedList list="Session_Reports__r"/>
</apex:page>

 Nothing very interesting - especially since I have cut this down for demonstration purposes.  Fields from the parent object are displayed, a related list is displayed.  This works.  Until...

 

Until I attempt to view this page as a user with a profile that has no access to the child object in the related list.  This user gets the following error message instead

 

'Session_Reports__r' is not a valid child relationship name for entity Appointment 

 

If I switch back to use the default layout constructed roughly in a similar manner - two fields and the same related list - the layout is displayed properly in all cases.  Users with access to the child object see the related list, users without no access to the child object see nothing at all (including no error message!).  This is exactly the behaviour I want to replicate using a VF page.  But I can not.

 

I have tried some tips found online - remove and re-add the related list in the layout in order to make the VF work was one of them and it made no difference - but have not succeeded in making this work. It seems like I have a fundamental misunderstanding of how this should work - I really expected to be able to put in apex:relatedList and have VF figure out if it could or could not display it based on the profile of the user.  Is that not the case?

 

Thanks for any advice you can provide.

Naidu PothiniNaidu Pothini

Did you try antying like using Rendered attribute in the related list?

 

I am not sure but if there is some way to check whether ther user have access or not, we can render it based on the user profile.

 

Try this.

 

<apex:relatedList list="Session_Reports__r" rendered="{!$ObjectType.Session_Reports__c.accessible}"/>
seallesssealless

I see what you are getting at in your recommendation but I will not be adopting such an approach.  There is no reason why a VF page should have to know if a user can or can not read a particular object.  As my example indicated this functionality is inherent in the standard default layout and I expect it to be replcated in VF.

Sealless2Sealless2

Utilizing $ObjectType and accessible is, in fact, the correct solution despite my reluctance to adopt it.  Sorry I cannot mark it as correct due to an inability to sign on under my previous user account.  Thank you for your tip.