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

Im working in a site, And I need to present many fields to be filled and the page, so accoding to a selecction before, I have all the field but I have the Api Name, and the object name, but, With this api object field name, how can I get the label????

Example. I have "Student__c", I need to present "Student" to the user.

Thanks a lot for ur help!

Ok, thanks for ur answuers but I think I did not explain well this situation.

I have a list of string, where I have the information but in Api's name. I present this fields in a table, so the user is filling the fields but with an inputText and not with an inputfield!.. So, in this moment, I dont know what is the label of each field.

My question basically, if by means of a query I could know the label of a field, if I know the api field name and the object name.. My question is if there is a way to consult this info!...

I know if I have the object is enough using an inputfield, But I cant do that. Neither set the label with HTML directly 'cause this is something dynamic.

Anyone knows how can I know, or consult, I guess by means of a query, how to get this label names???

share|improve this question
Are you creating a Visualforce page? – Scott Pelak Dec 20 '13 at 16:23
up vote 5 down vote accepted

Not sure if you can do it in pure visualforce. With Apex controller you'll be able to do something like this:

String objectName = 'Contact';
String fieldName = 'FirstName';

List<Schema.DescribeSObjectResult> describeSobjectsResult = Schema.describeSObjects(new List<String>{objectName}); // this can accept list of strings, we describe only one object here
String objectLabel = describeSobjectsResult[0].getLabel();
Map<String, Schema.SObjectField> allFields = describeSobjectsResult[0].fields.getMap();
String fieldLabel = allFields.get(fieldName).getDescribe().getLabel();

System.debug(objectName + '.' + fieldName + '  => ' + objectLabel + ', ' + fieldLabel);

Totally dynamic retrieval of object label & field label ;)

See for more goodies. Maybe it'd be possible in pure Visualforce with the ['string here'] syntax...

Also... exactly how dynamic you'll have to be? Check out the fieldsets in VF developer guide, might simplify your page greatly...

share|improve this answer
Not sure why this got downvoted, but this is the best way to do this. Anything else relies on hardcoding the label in code instead of referencing the metadata. – Michael Welburn Dec 20 '13 at 21:49
Hi @MichaelWelburn, thx for the kind words :) No idea really. We don't know how dynamic the solution has to be. If the fields point to some fields on some sObject(s) - I see only my way. If there is a concrete Account etc. somewhere in the controller - I like sfdcfox's way as it feels cleaner and closer to fieldsets solution. – eyescream Dec 21 '13 at 12:29
This is the real answer I was looking for!... So Thank you. I figure it out from another website, but its your same answer... – user4882 Dec 23 '13 at 21:20

Use $ObjectType global variable, and it could print the Student__c field label like this(please change the object name as needed)

<apex:outputLabel value="{!$ObjectType.CustomObject__c.fields.Student__c.Label}" />
share|improve this answer

An example of using the label attribute in a simple Visualforce Controller:

<apex:page standardController="My_Custom_Object__c" >
        <apex:pageBlock title="My Section Title">
            <apex:pageBlockSection columns="2" title="Section Header">
                <apex:inputField value="{!My_Custom_Object__c.Student__c}" label="Student"/>

Another more general example:

<apex:page standardController="My_Custom_Object__c" >
        <apex:outputText value="Student" styleClass="myLabel"/><apex:inputField value="{!My_Custom_Object__c.Student__c}"/>
share|improve this answer

You can generate labels dynamically:


public with sharing class dyno {
    public Account account { get; set; }
    public String[] fields { get; set; }
    { account = new Account();
      fields = new String[] { 'Name','Industry' };


<apex:page controller="dyno">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!fields}" var="field">
                <apex:column value="{!$ObjectType.Account.fields[field].Label}"/>
                <apex:column >
                    <apex:inputText value="{!account[field]}"/>
share|improve this answer

another simple way to display field label from apex, is like this (if the object and field is not to be dynamic) :


If it is to be displayed on vf, then you can use the following code :

<apex:outputText value="{!$ObjectType.Contact.fields.Student__c.Label}"/>
share|improve this answer

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.