To get the Id of record type use getRecordTypeId() method .
System.debug( recordType.getDeveloperName());
I hope this blog help you to learn something new . Please share with your Coders friends , don’t forget to subscribe our Youtubechannal.
How the code works
getRecordTypeInfos() on the object describe returns one RecordTypeInfo for each record type, and the loop prints its developer name. The Master record type always appears in the list, even if you created no record types.
A mistake in the Custom record types snippet
The second snippet uses isDefaultRecordTypeMapping() to find custom record types. That method only tells you whether the type is the default for the current user, so it does not separate Master from custom types. Use isMaster() instead.
This prints the developer name, the label and the Id of each custom record type. If you only want types the running user can use, also check rt.isAvailable().
FAQ
How do I get the Id of one record type by name? Use Contact.SObjectType.getDescribe().getRecordTypeInfosByDeveloperName().get('Your_Developer_Name').getRecordTypeId(). It does not need a SOQL query.
Why not query the RecordType object? You can, but the describe approach does not use up a SOQL query.