10

I'm using Schema.getGlobalDescribe() to walk through the list of sObjects in the system. The DescribeSobjectResult offers isCustomSetting(), which allows me to tell which objects are custom settings. What I haven't been able to determine is which of those custom settings are hierarchy and which are lists. Both have a SetupOwnerId field, although I don't believe it's meaningful for list settings.

Is there any way to tell the two object types apart with the API?

3
  • I've found a workaround for this issue. While the schemata of the Hierarchy and List custom settings are identical, Salesforce will raise a required field exception on insert if the Name field is null on a list setting but not a hierarchy setting. Similarly, a Field Integrity Exception is raised if the SetupOwnerId field is populated on a list setting, but not a hierarchy setting.
    – David Reed
    Sep 8, 2017 at 16:26
  • 4
    ... and a further, better workaround: the Name field is nillable (isNillable() returns true in its field describe) for Hierarchy settings only. It's required for List settings.
    – David Reed
    Sep 11, 2017 at 16:28
  • WoW! 3 years and still there is no better solution to this! Thanks David for saving my day. May 15, 2021 at 6:19

1 Answer 1

5

I just did a System.debug(xxx__c.SObjectType.getDescribe()) on a list custom setting an a hierarchical one and both output:

isAccessible=true;
isCreateable=true;
isCustom=true;
isCustomSetting=true;
isDeletable=true;
isDeprecatedAndHidden=false;
isFeedEnabled=false;
isMergeable=false;
isMruEnabled=false;
isQueryable=true;
isSearchable=true;
isUndeletable=true;
isUpdateable=true;

so I don't think there is anything that distinguishes them in the describe API. You are probably stuck with finding differences by using the methods or by querying or by updating.

1
  • Hi Keith, can you say more about what you mean by distinguishing them using the methods, queries, or updates? I haven't for the life of me been able to figure out how to do that given an Sobject token or name, since the uniquely hierarchy methods are static.
    – David Reed
    Sep 5, 2017 at 16:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .