Record Type related all methods can be accessed through Schema easily. These methods are part of the RecordTypeInfo Apex class. Before using these methods, ensure that you use the correct Object Name in Schema.
Check if Record Type is Active:Fetch RecordType Id from RecordType Name:Fetch RecordType Id from RecordType Developer Name:Fetch RecordType Name from RecordType Id:Fetch RecordType Name from RecordType Developer Name:Fetch RecordType Developer Name from RecordType Id:Fetch RecordType Developer Name from RecordType Name:Check if RecordType is Master RecordType:
Check if Record Type is Active:
1 2 3 4 5 |
Boolean isActive = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Job Application').isActive(); Boolean isActive2 = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Job_Application').isActive(); |
Fetch RecordType Id from RecordType Name:
1 2 3 |
Id recordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Job Application').getRecordTypeId(); |
Fetch RecordType Id from RecordType Developer Name:
1 2 3 |
Id recordTypeId = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Job_Application').getRecordTypeId(); |
Fetch RecordType Name from RecordType Id:
1 2 3 |
String recordTypeName = Schema.SObjectType.Contact.getRecordTypeInfosById().get('0122x000000MORS').getName(); |
Fetch RecordType Name from RecordType Developer Name:
1 2 3 |
String recordTypeName = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Job_Application').getName(); |
Fetch RecordType Developer Name from RecordType Id:
1 2 3 |
String recordTypeDevName = Schema.SObjectType.Contact.getRecordTypeInfosById().get('0122x000000MORS').getDeveloperName(); |
Fetch RecordType Developer Name from RecordType Name:
1 2 3 |
String recordTypeDevName = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Job Application').getDeveloperName(); |
Check if RecordType is Master RecordType:
The master RecordType is the default one that’s used when a record has no custom record type associated with it.
1 2 3 4 5 |
Boolean isMaster = Schema.SObjectType.Contact.getRecordTypeInfosByName().get('Job Application').isMaster(); Boolean isMaster2 = Schema.SObjectType.Contact.getRecordTypeInfosByDeveloperName().get('Job_Application').isMaster(); |
To get More Info about RecordTypeInfo class, Click Here
Also Check:
For any queries or suggestions, comment below.
Cheers … Happy Coding … 🙂