Tag Archives: Record Id

Find Object Type From Record ID Prefix

Standard and Custom Objects in Salesforce have three character prefixes which form the first part of the record ID. For example, an Account record with ID “001g000001jmmCA” has the prefix “001”, which is the prefix for the Account object.

In some scenarios, you may want to find out the name of the object associated with the prefix using Apex code.

Find the Object name based on Record ID prefix:

String objectName = SchemaGlobalDescribe.findObjectNameFromRecordIdPrefix('100');
System.debug('Object Name: '+ objectName);

Find the Object name based on record ID:

Id recordId = '001g000001jmmCA';
System.debug('Object Name: '+ recordId.getsobjecttype());