Home SALESFORCEAPEX Get Record Type ID Using Object Name

Get Record Type ID Using Object Name

We can get the Object Record Type Id values in multiple ways like using SOQL, getDescribSObject and below are some examples:

Example 1:

//Replace Object Name (API Name) and Record Type Name (Record Type API)
private static Id businessAccountRecTypeId = null;
private static Id getEventRecodTypeId() {
if (businessAccountRecTypeId == null) {
businessAccountRecTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get(‘Business_Account’).getRecordTypeId(); //Business_Account RecordType API value from Account Object
return businessAccountRecTypeId;

Example 2:
//Replace Object Name (API Name) and Record Type Name (Not Record Type API)

Id businessAccountRecTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get(‘Business Account’).getRecordTypeId();

Example 3:
This way to get a recordTypeId using SOQL query in Apex
[Select id from RecordType where sObjectType = ‘Account’ and developerName =’Business_Account’].id

Important Note:
Salesforce Developer Tips: How to get a RecordType Id by Name without SOQL, use always as per example 1 without using SOQL Query to retrieve Object Record Type ID.

Useful Links:



You may also like

Leave a Comment