7

I am working with salesforce data within SQL, and am trying to come up with a proper solution to handle polymorphism/polymorphic keys. I am aware of the easy ones (whatid/whoid in task and event), however I am wanting to find every example of polymorphism within Salesforce. Is there a definitive list that is available?

The second part of this question, is determining the proper way to 'lookup' these IDs. Making ~30 joins would kill the performance of my queries, so I am trying to establish a route forward to lookup these values.

3
  • 1
    summer 19 includes GA for polymorphic soql: releasenotes.docs.salesforce.com/en-us/summer19/release-notes/…
    – cropredy
    Commented Jun 3, 2019 at 20:03
  • Hi @cropredy - I have seen that. However, I am actually working with this data on prem, aka outside of SOQL. I will give that a try though, and see if I can figure out how to leverage SOQL in that process. Thanks for the suggestion!! Commented Jun 3, 2019 at 20:13
  • Searching the object reference for "ParentId" will find many of them, though with some false positives (eg Case & Account) and probably missing some others. But a good start in the absence of a definitive list. Commented Jun 3, 2019 at 20:15

1 Answer 1

13

You can run an anonymous script like the below to find out for a specific org all of the fields which are polymorphic lookups:

for (SObjectType sObjectType : Schema.getGlobalDescribe().values())
{
    for (SObjectField field : sObjectType.getDescribe().fields.getMap().values())
    {
        if (field.getDescribe().getReferenceTo().size() > 1)
        {
            system.debug(sObjectType + '.' + field);
        }
    }
}

In a fresh Trailhead Playground, for example, the standard objects returned are:

  • AcceptedEventRelation.RelationId
  • AccountShare.UserOrGroupId
  • ActivityHistory.OwnerId
  • ActivityHistory.WhatId
  • ActivityHistory.WhoId
  • AssetShare.UserOrGroupId
  • AttachedContentDocument.LinkedEntityId
  • Attachment.OwnerId
  • Attachment.ParentId
  • AuthConfigProviders.AuthProviderId
  • CampaignMember.LeadOrContactId
  • CampaignMember.LeadOrContactOwnerId
  • CampaignShare.UserOrGroupId
  • Case.OwnerId
  • CaseShare.UserOrGroupId
  • CaseTeamMember.MemberId
  • CaseTeamTemplateMember.MemberId
  • CollaborationGroupRecord.RecordId
  • CollaborationInvitation.SharedEntityId
  • CombinedAttachment.ParentId
  • ConsumptionSchedule.OwnerId
  • ConsumptionScheduleShare.UserOrGroupId
  • ContactRequest.OwnerId
  • ContactRequest.WhatId
  • ContactRequest.WhoId
  • ContactRequestShare.UserOrGroupId
  • ContactShare.UserOrGroupId
  • ContentDistribution.RelatedRecordId
  • ContentDocumentLink.LinkedEntityId
  • ContentNotification.EntityIdentifierId
  • ContentVersion.FirstPublishLocationId
  • ContentWorkspaceMember.MemberId
  • CustomBrand.ParentId
  • CustomBrandAsset.AssetSourceId
  • CustomHttpHeader.ParentId
  • Dashboard.FolderId
  • DeclinedEventRelation.RelationId
  • Document.FolderId
  • DuplicateRecordItem.RecordId
  • EmailMessage.RelatedToId
  • EmailMessageRelation.RelationId
  • EmailStatus.WhoId
  • EmailTemplate.FolderId
  • EntityDefinition.DataStewardId
  • EntitySubscription.ParentId
  • Event.OwnerId
  • Event.WhatId
  • Event.WhoId
  • EventChangeEvent.WhatId
  • EventChangeEvent.WhoId
  • EventRelation.RelationId
  • EventRelationChangeEvent.RelationId
  • ExternalDataUserAuth.ExternalDataSourceId
  • FeedAttachment.FeedEntityId
  • FeedAttachment.RecordId
  • FeedComment.FeedItemId
  • FeedComment.ParentId
  • FeedItem.ParentId
  • FeedLike.FeedEntityId
  • FeedLike.FeedItemId
  • FeedPollChoice.FeedItemId
  • FeedPollVote.FeedItemId
  • FeedRevision.FeedEntityId
  • FeedSignal.FeedEntityId
  • FeedSignal.FeedItemId
  • FeedTrackedChange.FeedItemId
  • FieldDefinition.BusinessOwnerId
  • FlowInterview.OwnerId
  • FlowInterviewShare.UserOrGroupId
  • FlowRecordRelation.RelatedRecordId
  • ForecastShare.UserOrGroupId
  • Group.OwnerId
  • Group.RelatedId
  • GroupMember.UserOrGroupId
  • Image.OwnerId
  • ImageShare.UserOrGroupId
  • Lead.OwnerId
  • LeadShare.UserOrGroupId
  • ListEmail.OwnerId
  • ListEmailIndividualRecipient.RecipientId
  • ListEmailRecipientSource.SourceListId
  • ListEmailShare.UserOrGroupId
  • LoginHistory.AuthenticationServiceId
  • LookedUpFromActivity.OwnerId
  • LookedUpFromActivity.WhatId
  • LookedUpFromActivity.WhoId
  • Macro.OwnerId
  • MacroShare.UserOrGroupId
  • Note.ParentId
  • NoteAndAttachment.ParentId
  • OpenActivity.OwnerId
  • OpenActivity.WhatId
  • OpenActivity.WhoId
  • OpportunityShare.UserOrGroupId
  • Order.OwnerId
  • OrderShare.UserOrGroupId
  • OrgDeleteRequest.OwnerId
  • OrgDeleteRequestShare.UserOrGroupId
  • OutgoingEmail.RelatedToId
  • OutgoingEmail.WhoId
  • OutgoingEmailRelation.RelationId
  • PermissionSet.LicenseId
  • ProcessInstance.TargetObjectId
  • ProcessInstanceHistory.ActorId
  • ProcessInstanceHistory.OriginalActorId
  • ProcessInstanceHistory.TargetObjectId
  • ProcessInstanceStep.ActorId
  • ProcessInstanceStep.OriginalActorId
  • ProcessInstanceWorkitem.ActorId
  • ProcessInstanceWorkitem.OriginalActorId
  • QuickText.OwnerId
  • QuickTextShare.UserOrGroupId
  • RecordAction.RecordId
  • RecordActionHistory.ParentRecordId
  • Report.OwnerId
  • SetupEntityAccess.SetupEntityId
  • StreamingChannel.OwnerId
  • StreamingChannelShare.UserOrGroupId
  • Task.WhatId
  • Task.WhoId
  • TaskChangeEvent.WhatId
  • TaskChangeEvent.WhoId
  • TodayGoal.OwnerId
  • TodayGoalShare.UserOrGroupId
  • TopicAssignment.EntityId
  • UndecidedEventRelation.RelationId
  • User.DelegatedApproverId
  • UserAppMenuCustomization.OwnerId
  • UserAppMenuCustomizationShare.UserOrGroupId
  • UserChangeEvent.DelegatedApproverId
  • UserEmailPreferredPerson.OwnerId
  • UserEmailPreferredPerson.PersonRecordId
  • UserEmailPreferredPersonShare.UserOrGroupId
  • UserProvisioningRequest.OwnerId
  • UserProvisioningRequestShare.UserOrGroupId
  • UserShare.UserOrGroupId
  • Vote.ParentId
  • WebLink.ScontrolId
0

You must log in to answer this question.

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