Using the RecordTypeInfo class allows us to get information about the Record Types and which one is set to default for the running user's profile.
The (Person) Account is however a special case, because it is can have 2 defaults set for a profile: one in the same way as other objects (see top section of image 1) but also a specific default record type for both a regular Account as well as a Person Account.
With the following piece of code we can retrieve the default Record Type for the running user and also output the results in the debug log:
Map<Id, Schema.RecordTypeInfo> recordTypeInfoMap = Schema.Account.getSObjectType().getDescribe().getRecordTypeInfosById();
Id defaultRecordtypeId;
for (RecordTypeInfo recordTypeInfo : recordTypeInfoMap.values()) {
System.debug(recordTypeInfo.getName() + ': ' + recordTypeInfo.isDefaultRecordTypeMapping());
if (recordTypeInfo.isDefaultRecordTypeMapping()) {
defaultRecordtypeId = recordTypeInfo.getRecordTypeId();
}
}
The result of this (based on the configuration shown in the image) would be a list like below:
[4]|DEBUG|Commercial Account: true
[4]|DEBUG|Domestic Account: false
... any other record type you have
[4]|DEBUG|Master: false
So using the isDefaultRecordTypeMapping()
method from the RecordTypeInfo class only retrieves the default Account Record Type that is set for Account in general, regardless of whether it is a Person Account or not.
Question: Is there a way to also retrieve from the Schema that Domestic Account is set as the Person Account Default Record Type?