I'm trying to list the Record Types that a user has access to. Unfortunately, this cannot be done through SOQL Query (IIRC) and the only choice I have would be to either use Schema.SObjectType (Apex) or Metadata API.
I have found a Source Code which adds this method:
// Returns a List of the Names of all RecordTypes
// available to the running user for a given SOBject type
public static List<String> GetAvailableRecordTypeNamesForSObject(
Schema.SObjectType objType
) {
List<String> names = new List<String>();
List<RecordTypeInfo> infos = objType.getDescribe().getRecordTypeInfos();
// If there are 2 or more RecordTypes...
if (infos.size() > 1) {
for (RecordTypeInfo i : infos) {
if (i.isAvailable()
// Ignore the Master Record Type, whose Id always ends with 'AAA'.
// We check the Id because Name can change depending on the user's language.
&& !String.valueOf(i.getRecordTypeId()).endsWith('AAA'))
names.add(i.getName());
}
}
// Otherwise there's just the Master record type,
// so add it in, since it MUST always be available
else names.add(infos[0].getName());
return names;
}
And can be run through Anonymous Apex using this block:
List <String> availableRecordTypes = GetAvailableRecordTypeNamesForSObject(Case.SObjectType);
System.debug(availableRecordTypes);
However, I'm getting this error.
Method does not exist or incorrect signature: void GetAvailableRecordTypeNamesForSObject(Schema.SObjectType) from the type anon
Can you help me correct the Source Code above? Thank you.
Source: here (Finding if which users have a record type available to them using SOQL)