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
PharaohgirlPharaohgirl 

Lookup field not appearing in master-detail relationship on Visualforce page

Hello,

I'm trying to create a page that allows users to add new records for a custom object with master-detail relationships.

Project_team__c is the parent and Contact__c and Rule_closeout_report__c are child objects (via master-detail).

The page I've created allows me to add information and save a new record, but the "Contact name" and "Rule closeout report" fields do not appear as lookup - they just allow the user to enter free text.

Provided the text is entered correctly, it works perfectly. But I want these fields to show as lookup fields. Could you please help me make this work?
 
<apex:page standardController="Project_team__c"  standardStylesheets="false" 
           applyBodyTag="false" applyHtmlTag="false" showHeader="false" sidebar="false" cache="true"  > 
	<apex:form>
		<html>
      		<body>

<style>
.buttons{background-color:#7D4082;background-image:none;color:#FFFFFF;font-weight:bold;font-size:120%;}          
   
.basictable, td {border-collapse: collapse; padding-right: 15px; font-size:90%; padding-top: 10px; padding-bottom: 10px; font-family:"Helvetica",sans-serif; } 
    
</style>          
                
			<apex:pageBlock title="Add project team members to your close-out report">
          
         			<table class=".basictable" >
                   	<tr>
                    <td><strong><apex:outputLabel value="Contact name:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Contact__c}"></apex:inputField></td>
                    <td><strong><apex:outputLabel value="Role:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Role__c}"></apex:inputField></td>
              		<td><strong><apex:outputLabel value="Notes:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Notes__c}"></apex:inputField></td>
					<td><strong><apex:outputLabel value="Project number:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Rule_closeout_report__c}"></apex:inputField></td>
                    </tr>
          			</table>
      
       		</apex:pageBlock>	 
     
            <br></br>
          	<div align="left" draggable="false" >
			<apex:commandButton styleClass="buttons" id="savenewteammember" value="Add new team member" action="{!save}" style="height:35px;width:18%;" />
        	</div>
			<br></br>          
                                                          
      		</body>
		</html>
	</apex:form>
</apex:page>

 

This is how it currently appears:

How it currently appears on screen

Best Answer chosen by Pharaohgirl
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Rowena,
Please try the below code:
 
<apex:page standardController="Project_team__c"  standardStylesheets="false" 
           applyBodyTag="false"  cache="true"  > 
	<apex:form>
		<html>
      		<body>

<style>
.buttons{background-color:#7D4082;background-image:none;color:#FFFFFF;font-weight:bold;font-size:120%;}          
   
.basictable, td {border-collapse: collapse; padding-right: 15px; font-size:90%; padding-top: 10px; padding-bottom: 10px; font-family:"Helvetica",sans-serif; } 
    
</style>          
                
			<apex:pageBlock title="Add project team members to your close-out report">
          
         			<table class=".basictable" >
                   	<tr>
                    <td><strong><apex:outputLabel value="Contact name:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Contact__c}"></apex:inputField></td>
                    <td><strong><apex:outputLabel value="Role:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Role__c}"></apex:inputField></td>
              		<td><strong><apex:outputLabel value="Notes:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Notes__c}"></apex:inputField></td>
					<td><strong><apex:outputLabel value="Project number:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Rule_closeout_report__c}"></apex:inputField></td>
                    </tr>
          			</table>
      
       		</apex:pageBlock>	 
     
            <br></br>
          	<div align="left" draggable="false" >
			<apex:commandButton styleClass="buttons" id="savenewteammember" value="Add new team member" action="{!save}" style="height:35px;width:18%;" />
        	</div>
			<br></br>          
                                                          
      		</body>
		</html>
	</apex:form>
</apex:page>

This worked for me.Hope this will be helpful
Thanks.​​​​​​​

All Answers

Raj VakatiRaj Vakati
Try this code .. wrapped them apex:pageBlockSection
 
<apex:page standardController="Project_team__c"  standardStylesheets="false" 
           applyBodyTag="false" applyHtmlTag="false" showHeader="false" sidebar="false" cache="true"  > 
	<apex:form>
		<html>
      		<body>

<style>
.buttons{background-color:#7D4082;background-image:none;color:#FFFFFF;font-weight:bold;font-size:120%;}          
   
.basictable, td {border-collapse: collapse; padding-right: 15px; font-size:90%; padding-top: 10px; padding-bottom: 10px; font-family:"Helvetica",sans-serif; } 
    
</style>          
                
			<apex:pageBlock title="Add project team members to your close-out report">
            <apex:pageBlockSection columns="4">

         			<table class=".basictable" >
                   	<tr>
                    <td><strong><apex:outputLabel value="Contact name:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Contact__c}"></apex:inputField></td>
                    <td><strong><apex:outputLabel value="Role:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Role__c}"></apex:inputField></td>
              		<td><strong><apex:outputLabel value="Notes:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Notes__c}"></apex:inputField></td>
					<td><strong><apex:outputLabel value="Project number:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Rule_closeout_report__c}"></apex:inputField></td>
                    </tr>
          			</table>
      
	    </apex:pageBlockSection >

       		</apex:pageBlock>	 
     
            <br></br>
          	<div align="left" draggable="false" >
			<apex:commandButton styleClass="buttons" id="savenewteammember" value="Add new team member" action="{!save}" style="height:35px;width:18%;" />
        	</div>
			<br></br>          
                                                          
      		</body>
		</html>
	</apex:form>
</apex:page>

 
PharaohgirlPharaohgirl

Hi Raj,

Thanks for your reply.

I tried that, but it didn't make a difference. Still no lookup fields.

Thanks,
Rowena

Raj VakatiRaj Vakati
I got it ..

Remove background-image:none; from the styles 
 
<apex:page standardController="Project_team__c"  standardStylesheets="false" 
           applyBodyTag="false" applyHtmlTag="false" showHeader="false" sidebar="false" cache="true"  > 
	<apex:form>
		<html>
      		<body>

<style>
.buttons{background-color:#7D4082;color:#FFFFFF;font-weight:bold;font-size:120%;}          
   
.basictable, td {border-collapse: collapse; padding-right: 15px; font-size:90%; padding-top: 10px; padding-bottom: 10px; font-family:"Helvetica",sans-serif; } 
    
</style>          
                
			<apex:pageBlock title="Add project team members to your close-out report">
            <apex:pageBlockSection columns="4">

         			<table class=".basictable" >
                   	<tr>
                    <td><strong><apex:outputLabel value="Contact name:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Contact__c}"></apex:inputField></td>
                    <td><strong><apex:outputLabel value="Role:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Role__c}"></apex:inputField></td>
              		<td><strong><apex:outputLabel value="Notes:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Notes__c}"></apex:inputField></td>
					<td><strong><apex:outputLabel value="Project number:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Rule_closeout_report__c}"></apex:inputField></td>
                    </tr>
          			</table>
      
	    </apex:pageBlockSection >

       		</apex:pageBlock>	 
     
            <br></br>
          	<div align="left" draggable="false" >
			<apex:commandButton styleClass="buttons" id="savenewteammember" value="Add new team member" action="{!save}" style="height:35px;width:18%;" />
        	</div>
			<br></br>          
                                                          
      		</body>
		</html>
	</apex:form>
</apex:page>

 
PharaohgirlPharaohgirl
Hi Raj,

Unfortunately still hasn't solved it :(

That style was just for the button, but I tried removing it anyway. Still the same result - no lookup fields.

Thanks,
Rowena
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi Rowena,
Please try the below code:
 
<apex:page standardController="Project_team__c"  standardStylesheets="false" 
           applyBodyTag="false"  cache="true"  > 
	<apex:form>
		<html>
      		<body>

<style>
.buttons{background-color:#7D4082;background-image:none;color:#FFFFFF;font-weight:bold;font-size:120%;}          
   
.basictable, td {border-collapse: collapse; padding-right: 15px; font-size:90%; padding-top: 10px; padding-bottom: 10px; font-family:"Helvetica",sans-serif; } 
    
</style>          
                
			<apex:pageBlock title="Add project team members to your close-out report">
          
         			<table class=".basictable" >
                   	<tr>
                    <td><strong><apex:outputLabel value="Contact name:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Contact__c}"></apex:inputField></td>
                    <td><strong><apex:outputLabel value="Role:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Role__c}"></apex:inputField></td>
              		<td><strong><apex:outputLabel value="Notes:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Notes__c}"></apex:inputField></td>
					<td><strong><apex:outputLabel value="Project number:"></apex:outputLabel></strong></td>
                    <td><apex:inputField label="" style="width: 85%; height: 25px" value="{!Project_team__c.Rule_closeout_report__c}"></apex:inputField></td>
                    </tr>
          			</table>
      
       		</apex:pageBlock>	 
     
            <br></br>
          	<div align="left" draggable="false" >
			<apex:commandButton styleClass="buttons" id="savenewteammember" value="Add new team member" action="{!save}" style="height:35px;width:18%;" />
        	</div>
			<br></br>          
                                                          
      		</body>
		</html>
	</apex:form>
</apex:page>

This worked for me.Hope this will be helpful
Thanks.​​​​​​​
This was selected as the best answer
PharaohgirlPharaohgirl
Thanks Bhargavi! That worked.

So using showHeader="false" prevents the lookup function from working. Anyone know why?

Rowena