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
RadDude89RadDude89 

Field labels not displaying on visualforce page

Hi,
I'm creating 2 columns on one of our visualforce pages and I am able to seperate the fields into 2 columns but whenever I get this happening the field labels are removed.  The visualforce page only shows the actual input text fields but not the labels.
Below is my code on the VF page:


<apex:pageBlockSection columns="2">
            <apex:pageblock title="Account Information">
                <apex:inputField label="Lead Status" value="{!newLead.Status}" required="true" /> <br> </br>
                <apex:inputField label="Fuel Type" value="{!newLead.Fuel_Type__c}" /> <br> </br>
                <apex:inputField label="Region" value="{!newLead.Region__c}" /> <br> </br>
                <apex:outputField value="{!newLead.RecordTypeId}" /> <br> </br>
                </apex:pageblock>
                <apex:pageblock title="Account Information 2">
                <apex:inputField value="{!newLead.Consumption__c}" /> <br> </br>
                <apex:inputField value="{!newLead.Dual_Fuel__c}" /> <br> </br>
                <apex:inputField value="{!newLead.Associated_Dual_Fuel_Site__c}" /> <br> </br>
                <apex:inputField value="{!newLead.Qualification_Check__c}" /> <br> </br>
                </apex:pageBlock>
            </apex:pageBlockSection>


Am I doing something wrong here?  Does anyone know how I can get the labels to appear?
Any help is much appreciated

Best Answer chosen by RadDude89
Rohit K SethiRohit K Sethi
Hi ,
Write the code 

<apex:pageBlockSection columns="2">
            <apex:pageblock title="Account Information">
                         <apex:pageBlockSection columns="1">
                                  <apex:inputField value="{!newLead.Status}" required="true" />
                          </apex:pageBlockSection>
             </apex:pageBlock>
</apex:pageBlockSection>

Thnaks.

All Answers

Rohit K SethiRohit K Sethi
Hi RadDude,

To Display label you need to define <apex:ouputLabel>. And use following syntax for outputLabel value
                         {!$ObjectType.ObjectName.fields['FieldName'].label}
Here is the code :
<apex:outputLabel value="{!$ObjectType.Lead.fields['Status'].label}" />
<apex:inputField  value="{!newLead.Status}" required="true" />
If this post solves your problem kindly mark it as solution.
Thanks

 
RadDude89RadDude89

Hi Rohit,

Thanks - this shows the field label now.

The only thing is the field label appears above the field input - is there a way in which the label can be placed on the same row as the input field?

Amit Chaudhary 8Amit Chaudhary 8
Please try to update your code like below.
<apex:pageblock >

	<apex:pageBlockSection columns="2" title="Account Information">
		<apex:inputField label="Lead Status" value="{!newLead.Status}" required="true" /> <br> </br>
		<apex:inputField label="Fuel Type" value="{!newLead.Fuel_Type__c}" /> <br> </br>
		<apex:inputField label="Region" value="{!newLead.Region__c}" /> <br> </br>
		<apex:outputField value="{!newLead.RecordTypeId}" /> <br> </br>
	</apex:pageBlockSection>

	<apex:pageBlockSection columns="2" title="Account Information 2">
		<apex:inputField value="{!newLead.Consumption__c}" /> <br> </br>
		<apex:inputField value="{!newLead.Dual_Fuel__c}" /> <br> </br>
		<apex:inputField value="{!newLead.Associated_Dual_Fuel_Site__c}" /> <br> </br>
		<apex:inputField value="{!newLead.Qualification_Check__c}" /> <br> </br>
	</apex:pageBlockSection>

</apex:pageBlock>
Please check below post for PageBlockSection
1) https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_pageBlockSection.htm

Let us know if this will help you

Thanks
Amit Chaudhary
Rohit K SethiRohit K Sethi
Hi ,
Write the code 

<apex:pageBlockSection columns="2">
            <apex:pageblock title="Account Information">
                         <apex:pageBlockSection columns="1">
                                  <apex:inputField value="{!newLead.Status}" required="true" />
                          </apex:pageBlockSection>
             </apex:pageBlock>
</apex:pageBlockSection>

Thnaks.
This was selected as the best answer
Sowmya AndeySowmya Andey
Hi ,
With this code I can only see input fields but not the labels ,also I have given columns="2" , but fields are being rendered in only one column , can someone tell me where I am wrong ?
<apex:page standardcontroller="account" tabstyle="Branch__c" setup="false" sidebar="false" showheader="true">
  <apex:sectionHeader title="Account Edit" subtitle="New Account" />
    <apex:form >
      <apex:pageblock title="Account edit">
               <apex:pageblockbuttons location="both">
                     <apex:commandbutton value="Edit"/>
                     <apex:commandbutton value="Save"/>
                     <apex:commandbutton value="Cancel"/>
               </apex:pageblockbuttons>
               <apex:pageblocksection title="Account Details " columns="3" collapsible="true"/> 
               
                     <apex:inputfield label="Name" value="{!account.Name}"/> <br></br>
                     <apex:inputfield Label="Parent ID" value="{!account.parentid}"/> <br></br>
                     <apex:inputfield value="{!account.AccountNumber}"/> <br></br>
                     <apex:inputfield value="{!account.Type}"/> <br></br>
                     <apex:inputfield value="{!account.Industry}"/> <br></br>
                     <apex:inputfield value="{!account.AnnualRevenue}"/><br></br>
                     <apex:inputfield value="{!account.Phone}"/> <br></br>
                     <apex:inputfield value="{!account.Fax}"/> <br> </br>
                     <apex:inputfield value="{!account.Rating}"/> <br></br>
                     <apex:inputfield value="{!account.Website}"/> <br></br>
                     <apex:inputfield value="{!account.Ownership}"/> <br></br>
                     
                 
                     
               <apex:pageblocksection title="Related cases " collapsible="true"/>
               <apex:pageblocksection title="Related Contacts " collapsible="true"/> 
               <apex:pageblocksection title="Related Opportunities" collapsible="true"/>                                      
     </apex:pageblock>   
   </apex:form>       
</apex:page>