I want to fetch type of hierarchy setting(profile OR User), compare it and do some logic. For that I am using setupOwner.Type in SOQL query as:

SELECT SetupOwner.Name,SetupOwner.Type,SetupOwnerId, Field1__c,
            FROM MyUserSettings__c
            ORDER BY SetupOwner.Name

It is giving me output as:

> SetupOwner.Type for User: 'User'
> SetupOwner.Type for profile: '00e'
> SetupOwner.Type for org: '00D'

But when I use where clause:

 where SetupOwner.Type='00e'

it gives me 0 results.

How can we obtain records where type is 'Profile'? Or what is the API name of field 'Location' in hierarchy settings?

Also, I could not find official documentation for 'SetupOwner'. Is there any?

  • @Reshma : Yes, but it does not have ans required by me.
    – Sarang
    Commented Jan 24, 2017 at 8:35

1 Answer 1


That is not a custom setting feature, you are referring to a polymorphic field, refer Cross-Object Owner Fields.

Now you can add filter after querying:

for(OverrideStandardButtons__c setting: [SELECT Name, 
    SetupOwnerId FROM OverrideStandardButtons__c]) {
    if(setting.SetupOwnerId.getSObjectType() == User.SObjectType ||
        setting.SetupOwnerId.getSObjectType() == Profile.SObjectType) {
        System.debug('ownerType: ' + setting.Name);

Credit goes to sfdcfox!


For your example, simpler would be to use following query:

SELECT Name, SetupOwnerId, SystemModstamp FROM OverrideStandardButtons__c WHERE SetupOwnerId NOT IN (SELECT Id FROM Organization)

  • Thanks for the query and answer, I need to study cross-object Owner fields. I modified your query to: SELECT SetupOwner.Name , SetupOwnerId FROM OverrideStandardButtons__c WHERE SetupOwnerId NOT IN (SELECT Id FROM Organization) Because I wanted name of the Profile/User, but for profile name, it is showing me 8 instead of Standard Platform User. Can you please calrify this as well?
    – Sarang
    Commented Jan 24, 2017 at 9:00
  • 1
    You cannot retrieve the field directly, you have to use typeof to retrieve data from polymorphic relationship!
    – Raul
    Commented Jan 24, 2017 at 9:09

You must log in to answer this question.

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