Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I have the following markup on a Visualforce Page:

<apex:pageBlockSection title="Account" columns="1">
    <apex:inputField value="{!CurrentOrder.AccountId}"/>
</apex:pageBlockSection>

Also:

<apex:outputLabel value="{!$ObjectType.Order.fields.AccountId.Label}"/>
<apex:inputField value="{!CurrentOrder.AccountId}"/>

The First markup renders the label as "Account Name".

The Second markup renders the label as "Account Id"

I don't understand why the 2 would be different. I'm using the same Object and Field. Can someone clarify?

share|improve this question

1 Answer 1

It's a little esoteric, I think. You are asking VF to create an input field for an ID, which can't be changed. So it is converting it to a name, which can be used properly in an input field. I might have to double check that, but it fits in line with how most VF components work. Otherwise you get a bound field which if the user updates will return a controller error.

The labels are different because in the first case VF has done the translation I describe above, but in the second case you are creating a distinct output label pointing to the entry in the describe field (so it is unaware such a translation is going to take place)

share|improve this answer
    
Shouldn't the inputField markup that is bound to Order.AccountId get it's label from the same place that $ObjectType.Order.fields.AccountId.Label comes from? They both reference the Order.AccountId field. I've also seen this happen on Opportunity.AccountId. This also happens on Order.BillToContactId. If I'm asking for a Label, I should get the same value whether it's bound using inputField or through the $ObjectType.Order.fields.AccountId.Label which it looks like is using describe to get values. –  myForceDotCom Aug 5 at 16:29
    
Yeah sorry, my answer was a little incomplete. Updated. –  joshbirk Aug 5 at 16:54
    
Is there a way to get to the translated "Account Name" label value without using the inputField markup? Also If I override the Label in "Rename Tabs and Labels" for Bill To Contact, both mark up ways will render the overridden value. –  myForceDotCom Aug 5 at 18:24
    
For added fun - if your org has currencies enabled - compare the label of the picklist and the picklist options on regular page and on VF page ;) –  eyescream Aug 5 at 21:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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