Today, we will learn how we can check whether the given custom setting is List of Hierarchy.
To Understand custom settings click here.
Apex Code:
String api = 'customSettingName__c';
Type reflector = Type.forName(api);
SObject sobj=(SObject)reflector.newInstance();
DescribeSObjectResult sobjResult =
sobj.getSObjectType().getDescribe();
//some Name field info
SObjectField field =
sobjResult.Fields.getMap().get('Name');
DescribeFieldResult fieldResult =
field.getDescribe();
Integer length = fieldResult.getLength();
system.debug('length-'+length);
If length is 38 that means it is list, if length is 80 that means it is hierarchy
Please share your thoughts on this if there is any other way to do so.