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

REG: contact's First Name(with Salutation) in the VF page

Hi Dev,


I am creating a VFPage which creates a contact. I am using Standard controller and inputfield for that.


Now the Problem is I am not getting the salutation inside the FirstName. How to do it?


Example:    FirstName : [  [\/]] [                    ]

       |             |

                                   Salutation    FirstName





Best Answer chosen by Admin (Salesforce Developers) 

I dont really understand your example but Im guessing that your problem is that your salutation field and first name field are being separated inside the page block into two different columns.


You need to wrap the two fields inside an apex:pageblocksectionitem component:



<apex:pageBlockSectionItem >
    <apex:outputlabel value="First Name"/>
    <apex:outputpanel >
        <apex:outputfield value="{!Contact.Salutation}" />
        <apex:outputfield value="{!Contact.FirstName}" />


The pageblocksectionitem ensures that it's contents are displayed as one field.

The output label displays the label you want - you need this because the pageblocksectionitem removes all formatting so the inputfield's label will NOT be displayed.

A pageblocksectionitem can only contain two children so to I've used outputpanel to wrap the three further components that we require - the two fields separated by a non breaking space.


This should work!