function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Taro UraokaTaro Uraoka 

How to get "Record Type" (Not "Record Type ID") as label of RecordTypeId field in Apex or REST API

Following code:
<apex:page controller="MyCustomObject__c">
    <apex:pageBlock>
        <apex:pageBlockSection>
            <apex:outputField value="{!MyCustomObject__c.RecordTypeId}"/>
        </apex:pageBlockSection>
    </apex:pageBlock>
</apex:page>
I got:
User-added image
<apex:outputField> put "Record Type" as label of RecordTypeId field.

And I want to reproduce this by Apex Describe Information or REST API, because I want to build page dynamically.

Account.MyCustomObject__c.RecordTypeId.getDescribe().getLabel() returns 'Record Type ID'.
SObject Describe endpoint ( /services/data/v41.0/sobjects/MyCustomObject__c/describe ) responds "Record Type".
How can I get "Record Type" (Not "Record Type ID") ?
Taiki YoshikawaTaiki Yoshikawa
Hi, I got the record type label.
String result = Schema.getGlobalDescribe().get('Account').getDescribe().getRecordTypeInfosById().get('<RecordTypeID>').getName();
System.debug(result);

 
Taro UraokaTaro Uraoka
Sorry, I want "Record Type" as label of FIELD, not a label for individual Record Type.

I found solution:
Schema.SObjectType.RecordType.getLabel();



 
Taiki YoshikawaTaiki Yoshikawa
Great!