[SalesForce] How to get Object Label

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

Best Answer

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


Related Topic