Owner custom fields and some standard fields are not accessible in relations

Unfortunately the Owner relation is a kind of strange.

Even if you prefix it the right way: it fails. This strange behavior seems not to be related to Managed Packages but the polymorphic nature of the Owner field. It was already noticed for some standard fields here.

Background

For Lead, Case, Knowledge article, Service contract and CustomObjects the Owner-field can not only be of type "User", but also of type "Group". Reason is, that the owner can also be a queue.

Like @PeterKnolle stated in the comment, in cases of such polymorphic foreign keys an SObject of type Name will be used.

So all this applies only, if you select owners of Cases or CustomObject and not if you do the same query on e. g. Account.

So this works:

SELECT Name, OwnerId, Owner.Name, Owner.Street FROM Account

while this doesn't:

SELECT Name, OwnerId, Owner.Name, Owner.Street FROM YourPrefix__YourObject__c

Now if we recognize the polymorphism, what could be meaningful? I would expect to:

  • either be able to access all fields of both possible objects-types (merged, keeping the non-existent columns NULLed for the records of the other type)
  • or only those which are present in both (intersecting set of fields).

But the reality is different.

Status Quo

What I have tried so far, goes like this:

  • works:

    • Owner.Name
    • Owner.Id
    • Owner.Type
    • Owner.Email
    • Owner.Username
    • Owner.LastName
    • Owner.FirstName
    • Owner.Title
    • Owner.Phone
    • Owner.Alias
    • Owner.UserRoleId
    • Owner.ProfileId
    • Owner.LastReferencedDate
    • Owner.Owner.LastViewedDate
  • fails:

    • Owner.AnyCustomField__c
    • Owner.DeveloperName
    • Owner.RelatedId
    • Owner.OwnerId
    • Owner.DoesSendEmailToMembers
    • Owner.DoesIncludeBosses
    • Owner.CreatedDate
    • Owner.CreatedById
    • Owner.LastModifiedDate
    • Owner.LastModifiedById
    • Owner.SystemModstamp
    • Owner.CompanyName
    • Owner.Division
    • Owner.Department
    • Owner.Stree and all other Adress-Fields
    • Owner.Longitude and Latitude
    • Owner.StayInTouchNote
    • Owner.StayInTouchSignature
    • Owner.StayInTouchSubject
    • Owner.Signature
    • Owner.SenderName
    • Owner.SenderEmail
    • Owner.EmailPreferencesStayInTouchReminder
    • Owner.EmailPreferencesAutoBccStayInTouch
    • Owner.Fax
    • Owner.MobilePhone
    • Owner.CommunityNickname
    • Owner.Active
    • Owner.TimeZoneSidKey
    • Owner.LocaleSidKey
    • Owner.ReceivesInfoEmails
    • Owner.EmailEncodingKey
    • Owner.ReceivesAdminInfoEmails
    • Owner.OfflineTrialExpirationDate
    • Owner.LastPasswordChangeDate
    • Owner.LastLoginDate
    • Owner.ManagerId
    • Owner.DelegatedApproverId
    • Owner.EmployeeNumber
    • Owner.LanguageLocaleKey
    • Owne
    • Owner.DefaultGroupNotificationFrequency
    • Owner.DigestFrequency
    • Owner.SmallPhotoUrl
    • Owner.FullPhotoUrl
    • Owner.AboutMe
    • Owner.FederationIdentifier
    • Owner.Extension
    • Owner.CallCenterId
    • Owner.AccountId
    • Owner.ContactId
    • Owner.UserPreferencesHideS1BrowserUI
    • Owner.UserPreferencesShowCountryToGuestUsers
    • Owner.UserPreferencesShowPostalCodeToGuestUsers
    • Owner.UserPreferencesShowStateToGuestUsers
    • Owner.UserPreferencesShowCityToGuestUsers
    • Owner.UserPreferencesShowTitleToGuestUsers
    • Owner.UserPreferencesShowProfilePicToGuestUsers
    • Owner.UserPreferencesShowCountryToExternalUsers
    • Owner.UserPreferencesShowPostalCodeToExternalUsers
    • Owner.UserPreferencesShowStateToExternalUsers
    • Owner.UserPreferencesShowCityToExternalUsers
    • Owner.UserPreferencesShowStreetAddressToExternalUsers
    • Owner.UserPreferencesShowFaxToExternalUsers
    • Owner.UserPreferencesShowMobilePhoneToExternalUsers
    • Owner.UserPreferencesShowWorkPhoneToExternalUsers
    • Owner.UserPreferencesShowEmailToExternalUsers
    • Owner.UserPreferencesShowManagerToExternalUsers
    • Owner.UserPreferencesShowTitleToExternalUsers
    • Owner.UserPreferencesDisableFileShareNotificationsForApi
    • Owner.UserPreferencesEnableAutoSubForFeeds
    • Owner.UserPreferencesDisableSharePostEmail
    • Owner.UserPreferencesDisableBookmarkEmail
    • Owner.UserPreferencesOptOutOfTouch
    • Owner.UserPreferencesDisableMessageEmail
    • Owner.UserPreferencesDisableLikeEmail
    • Owner.UserPreferencesDisCommentAfterLikeEmail
    • Owner.UserPreferencesHideSecondChatterOnboardingSplash
    • Owner.UserPreferencesHideChatterOnboardingSplash
    • Owner.UserPreferencesHideCSNDesktopTask
    • Owner.UserPreferencesDisMentionsCommentEmail
    • Owner.UserPreferencesDisableMentionsPostEmail
    • Owner.UserPreferencesHideCSNGetChatterMobileTask
    • Owner.UserPreferencesApexPagesDeveloperMode
    • Owner.UserPreferencesContentEmailAsAndWhen
    • Owner.UserPreferencesContentNoEmail
    • Owner.UserPreferencesDisProfPostCommentEmail
    • Owner.UserPreferencesDisableLaterCommentEmail
    • Owner.UserPreferencesDisableChangeCommentEmail
    • Owner.UserPreferencesDisableProfilePostEmail
    • Owner.UserPreferencesDisableFollowersEmail
    • Owner.UserPreferencesDisableAllFeedsEmail
    • Owner.UserPreferencesReminderSoundOff
    • Owner.UserPreferencesTaskRemindersCheckboxDefault
    • Owner.UserPreferencesEventRemindersCheckboxDefault
    • Owner.UserPreferencesActivityRemindersPopup
    • Owner.ForecastEnabled
    • Owner.UserPermissionsChatterAnswersUser
    • Owner.UserPermissionsSiteforcePublisherUser
    • Owner.UserPermissionsSiteforceContributorUser
    • Owner.UserPermissionsSupportUser
    • Owner.UserPermissionsInteractionUser
    • Owner.UserPermissionsKnowledgeUser
    • Owner.UserPermissionsSFContentUser
    • Owner.UserPermissionsMobileUser
    • Owner.UserPermissionsCallCenterAutoLogin
    • Owner.UserPermissionsOfflineUser
    • Owner.UserPermissionsMarketingUser
    • Owner.OfflinePdaTrialExpirationDate

Since that question is still actual, i find helpful to share the way around i found for myself to filter records by Owner's custom field value.

My goal was to filter activities by owner's Primary Function which is a custom picklist field.

So i added a custom formula field named Owner_Primary_Functions__c to Activities object to represent the field value from related User objects for Task records. In my case the formula was TEXT(Owner:User.Primary_Functions__c).

Now this query works for me:

SELECT Id, Subject, Owner.Name, Owner_Primary_Functions__c FROM Task
    WHERE Owner_Primary_Functions__c = :someFunction