[SalesForce] Display parent as lookup field on child in visualforce page

I have two objects SFDC_PTO_Request__c (child),Employee__c (parent) with Master-Detail relationship. I need to display parent on child record while inserting on visualforce page which was a lookup relationship. I am trying as below

<apex:page standardController="SFDC_PTO_Request__c" recordSetVar="SFDC_PTO_Request" sidebar="false">
 <apex:form >
 <apex:pageBlock title="Leave Request Edit">
 <apex:pageBlockButtons >
     <apex:commandButton action="{!Save}" value="Save"/>
     <apex:commandButton action="{!Cancel}" value="Cancel"/>
 </apex:pageBlockButtons>
 <apex:pageBlockSection title="Information" columns="2" collapsible="false">
      <apex:inputField value="{!SFDC_PTO_Request__c.Type_of_leave__c}"/>
      <apex:inputField value="{!SFDC_PTO_Request__c.Available_Casual_Leaves__c}"/>     
      <apex:inputField value="{!SFDC_PTO_Request__c.Available_Sick_Leaves__c}"/>   
      <apex:inputField value="{!SFDC_PTO_Request__c.Request_Type__c}"/>   
      <apex:inputField value="{!SFDC_PTO_Request__c.Employee__c}"/>
 </apex:pageBlockSection>
  <apex:pageBlockSection title="Request Dates" columns="2" collapsible="false">
      <apex:inputField value="{!SFDC_PTO_Request__c.Request_Start_Date__c}"/>
      <apex:inputField value="{!SFDC_PTO_Request__c.Request_End_Date__c}"/>  
 </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

enter image description here

could some one help me to display the lookup field of parent on child record

Best Answer

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.

Related Topic