I have object's API Name

How can I get Object's Label ?

I am trying this

Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();

Schema.SObjectType schemaObj = schemaMap.get(SObjApiName);

You can retrieve label of given object like this:

String objectName = 'Contact';

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();


| improve this answer | |
    String type = 'Account';

    Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
    Schema.SObjectType leadSchema = schemaMap.get(type);
    Map<String, Schema.SObjectField> fieldMap = leadSchema.getDescribe().fields.getMap();

    //to get single field label in account

    //to get all field labels
    for (String fieldName: fieldMap.keySet()) {
      // list of all field API name
      System.debug('-->Field API Name='+fieldName);

      //It provides to get the object fields label.
| improve this answer | |
  • 1
    I guess Yogesh is asking for label of object and not fields. – Mr.Frodo Jun 17 '16 at 5:16
  • oh yea, i missed that! oops – sfdcFanBoy Jun 17 '16 at 7:06

Just try this code if you want to retrive the object name from a string in visualforce page.

public string selectedobject{get;set;}
public sObject sObj{get;set;} 
Map m  = Schema.getGlobalDescribe() ;  
Schema.SObjectType s = m.get(selectedobject) ;    
sObj =s.newSObject();
| improve this answer | |

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