In my controller I have a List of string. This list contains The Object Name, and the Field Name. So, I need to get the "Label" Name of this fields.

I need to make a query where the conditions is the object name and the fieldname.

Please take consideration that this is Dynamic, So, I cant just simply create a list of the object because in this list of string I may have any object of the whole solution.

So, I dont know how to make this query to the metadata, in order to know the labels name of my list string of fields. Example:

I have "Student__c" in a variable, I need to get "Student" in another variable. but it gotta be the "real" label of the respective object.

and it can be a plenty of fields, so cant not be hardcore. It have to be consulting in somewhere the correct label, but I dont know where to consult. I'll really appreciate your help!


Have you looked into Dynamic Apex? If you know the Object API Name, you can retrieve it via a Describe call, and then access the fields using the fields method, which allows you get access the field names as keys from a getMap() call.

The following isn't the most efficient for reuse, but you should be able to glean what methods you'll need to leverage.


| improve this answer | |

Assuming you know the name of the object and the field (I would presume so!), you can use this directly in Visualforce:

| improve this answer | |
  • would this work like this: <apex:outputLabel value="{!$ObjectType.Request_for_System_Change__c.fields.Any_additional_comments_Data_Request__c.Label}+':'"/> for my object Request_for_System_Change__c and the field called Any_additional_comments_Data_Request__c – Our Man in Bananas Jan 11 '16 at 13:01

This is the answer I was looking for!

   String type= 'MyCustomObject__c';  // Say,this is my object
   Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    Schema.SObjectType leadSchema = schemaMap.get(type);
    Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();
    for (String fieldName: fieldMap.keySet()) {  
        String mylabel;
          //It provides to get the object fields label.
         mylabel = fieldMap.get(fieldName).getDescribe().getLabel();
| improve this answer | |
  • Eh. So you really didn't actually bother to check the answers from your old question? I've posted pretty much same thing for you: salesforce.stackexchange.com/a/22775. At least please mark your answer as accepted so it goes "off the radar". – eyescream Dec 23 '13 at 21:00

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