10

I am trying to add a custom label to an apex:outputField tag but when I do the help text disappears. How do I change the label but keep the help text?

The VF snippet below displays the same field three different ways. The first two uses a custom label and the third is the normal apex:outputField which will use the label from the SObject field. The output is shown below the code.

    <apex:pageBlockSection title="Balances" columns="1">

        <apex:pageBlockSectionItem >
            <apex:outputLabel value="My Label"/>
            <apex:outputField value="{!sob.Balance__c}"/>
        </apex:pageBlockSectionItem>

        <apex:outputField value="{!sob.Balance__c}" label="My Label"/>

        <apex:outputField value="{!sob.Balance__c}"/> 

    </apex:pageBlockSection>

Here is the output. The help text only appears on the third field.

HelpText

2 Answers 2

13

The solution is easy. Just use the helpText attribute of the apex:pageBlockSectionItem and put the help info from the field in it:

<apex:pageBlockSectionItem helpText="{!$ObjectType.Account.fields.Street__c.InlineHelpText}">
    <apex:outputLabel value="My Label"/>
    <apex:outputField value="{!a.Street__c}"/>
</apex:pageBlockSectionItem>
2

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_pageBlockSectionItem.htm

This is not a bug and works as designed and discussed in above document .

Note that if you include an <apex:outputField> or an <apex:inputField> component in an <apex:pageBlockSectionItem>, these components do not display with their label or custom help text as they do when they are children of an <apex:pageBlockSection>. Also note that <apex:pageBlockSectionItem> components can't be rerendered; rerender the child components instead.

2
  • Does the same hold true for <apex:outputField value="{!sob.Balance__c}" label="My Label"/>?
    – BarCotter
    Nov 28, 2013 at 17:25
  • Yes i observed the same behaviour .I think mast0r has right work around Nov 28, 2013 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.