Salesforce Describe Methods – Record Types, Fields, and Global Describe

Record Type Describe

Getting an object’s record type Id is simple with the statement below, and it avoids using a SOQL statment on the RecordType object. However, the method name is misleading because getRecordTypeInfosByName actually retrieves the record type with the Label and not the Name. Also, be careful because the name is case sensitive. A Null Pointer Exception will be thrown if the label does not match exact spelling and case, so add appropriate error handling.


Retrieving Record Type information into a map is useful when more than one record type is needed in your logic.

sObject Field Describe

This gets a map of field tokens for an sObject type, and then the field describe method can be used to get a lot of useful information about the field. It excellent for making code flexible enough to work with variety of objects like I did with my In-line Editing Visualforce Component.

Here is a link to the Salesforce documentation on all of the field describe result methods.

Global Describe

Global describe returns a map of sObject tokens for all sobjects. Use this to get the sobject type for the describes above and others o.

Combine Global Describe with describing an Objects fields:

Here is a link to the Salesforce documentation on all of the object describe result methods.

Bounus: SObject Type from a Record Id

The Schema.SObjectType can also be retrieved from a Record Id. It is great when working with Task and Event WhatId fields because they can refer to multiple types of objects. Also, useful for Visualforce Page Controllers that have a record Id passed into the constructor method.