Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to get the label of a field without doing a loop on all object fields like this :

Map<String, SobjectField> fieldMap = Account.getsObjectType().getDescribe().Fields.getMap(); 
for(String f :  fieldMap.keySet())

Something like this :

String label = Account.getField('myFieldName').getLabel();
share|improve this question
Do you intend to you use it in a visualforce page? – melmoussaoui Apr 22 '14 at 9:35
Yes that's the goal. – SF_user Apr 22 '14 at 9:36
up vote 3 down vote accepted

If you want to do this in VisualForce you can use the following pattern:


Account can also be replaced by ['Account'] in the above line

If you have a List of field names that you need to iterate over then you can use the apex:repeat tag. See the example below

<apex:repeat value="{! fieldNames}" var="fieldName"> 
    <apex:outputText value="{!$ObjectType.Account.Fields.[fieldName].Label}">
share|improve this answer
That's what I need, thanks ! – SF_user Apr 22 '14 at 12:01

In Apex code, if you want the label of a field that you know about at compile time you can directly use the SObjectField reference (Account.BillingCity in this case but can be your custom fields too) and get the describe information from that:

String label = Account.BillingCity.getDescribe().getLabel();

But if you only know the field name at runtime, there is a map available on the fields collection that you can use without a loop. For example:

String label = Account.SObjectType.getDescribe().fields.getMap().get('BillingCity').getDescribe().getLabel();

PS Just noticed the comment that you want to do this in Visualforce not Apex. So you should follow BarCotter's approach.

share|improve this answer
This can also be done directly in VisualForce using this pattern: {!$ObjectType.Account.Fields.['BillingCity'].Label} – BarCotter Apr 22 '14 at 10:04
@BarCotter : I don't know the name of the field. It's on a loop so can I do something like : {!$ObjectType.Account.Fields.[myLoop[i]].Label} where myLoop[i] represent an Account field ? – SF_user Apr 22 '14 at 10:11
I have added an answer with the details – BarCotter Apr 22 '14 at 10:34

then use this :


Where Name is you field

share|improve this answer
I see this but the problem is that I have a random Account fields list. I have to loop on all fields and get the field label. I already ask about it (in Javascript) :… – SF_user Apr 22 '14 at 9:39
Ah, then in this case I don't think that you have another choice than what you already did in you question. – melmoussaoui Apr 22 '14 at 9:42
You speak about the loop ? – SF_user Apr 22 '14 at 9:43
Yes. I don't know about another way to get dynamically fields and labels for an SObject, and the simplest way as @Keith C told you. if you already knew the field name. – melmoussaoui Apr 22 '14 at 9:52

Your Answer


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.