Get Label For SObject API Name

  • I have an exhaustive list of custom objects whose API Names and labels does not match. I end up opening each object in order to determine if the label has matching API Name.I want to see the API Name displayed along with label on the result page of custom Objects. Is there a better way to get label for a custom object when its API Name is known?

  • You can get the label using the DescribeSObjectResult:

    DescribeSObjectResult describe = SObjectType.MyApiName__c;
    system.debug(describe.getLabel());
    

    Another common syntax is:

    DescribeSObjectResult describe = MyApiName__c.sObjectType.getDescribe();
    

    You can also just one-line it:

    system.debug(SObjectType.MyApiName__c.getLabel());
    

    I am looking to do it from the platform, not from the code. A soql query will also help.

    You cannot use a query. What do you mean by *from the platform*?

    When I log into my org I do a search for objects which has more than 500 objects. I know the API Name and want to navigate to that object but I end of opening each object to see if that is the object I am looking for or not.

    You are really not making yourself clear. Sorry.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM