Sunday, December 23, 2018

How to get Record Type Developer Name in Apex?


This post explains how to get the record type developer name in the apex.

Getting Record Type Id using Developer Name

Let assume Record Type Developer Name  is "Customer_Account" on Account Object
you want id of the Record type use below sample code

Example

Id idRecordId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('Customer_Account').getRecordTypeId();
System.debug('RecordTypeId based on Developer Name ---> '+idRecordId);
the above code returns the Record type Id based on developer name

Getting Record Type Developer Name

Let assume Record Type Name  is "Cluster Account" on Account Object
you want Developer Name of the Record type use below sample code

Example

String strRecordDevName = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Cluster Account').getDeveloperName();
System.debug('Record Developer Name ====> '+strRecordDevName);
the above code returns the developer name based on the record type name
Assume you have record type id instead of name use below sample code
String strRecordDevName = Schema.SObjectType.Account.getRecordTypeInfosById().get('012w0000000kgdfAAQ').getDeveloperName();
System.debug('Record Developer Name ====> '+strRecordDevName);
Let us know if have any queries
Happy Learning!!!

No comments:

Post a Comment