I'm creating a custom object that needs to be related to multiple other objects (but only one per record). I.e. via a ParentId field it could be related to a Opportunity, a Contact, an Account, or another custom object.

This would be pretty much the same as the Polymorphic Key Attachment.ParentId that can reference multiple other object types.

I can't do this via the UI as the lookup can only be related to a single type.

New Lookup Relationship

Is it possible to create a polymorphic reference through another means, such as the metadata api?

Failing that, are there any viable alternatives?

I'd like to use the lookup so I can show the related objects via the page layouts. This object will also be deployed as part of a managed package and clients may want to reference their own custom objects from it.

  • Is it viable to appropriate FeedItem / Event / Task / Note perhaps with RecordType? Jan 23, 2016 at 17:57
  • @bigassforce Would you then link to the correct object type via a dedicated field, or just rely solely on different sets of fields with RecordType. Seems like it could be messy quickly. Especially if those objects are otherwise in use already. Jan 28, 2016 at 8:47
  • 1
    Good question, the appropriateness depends on how taskful / eventful / noteful that "data" is. User may not want ToiletBreak__c on their calendar 😬 Jan 28, 2016 at 12:45

1 Answer 1


As of now, polymorphic keys only exist as standard fields. See the idea - Custom Polymorphic Id field (WhoId/WhatId)

To mimic the functionality by say using a custom text field, would be a rigorous customization:

  1. Custom text field, mark as ExternalId for indexing purpose.
  2. UI control...probably would have to be custom visualforce + apex controller.
  3. Related Lists...again, custom visualforce + apex controller.
  4. Probably some other stuff I can't think of right now, but that would be the minimum as I envisage it.
  • This is the conclusion I'd come to, but I thought I'd try my luck to see if anyone had any other ideas. I'll add a link to an existing idea into your post. Oct 18, 2012 at 0:15
  • Thanks for adding the link. Will look at it and likely vote it up!
    – pchittum
    Oct 18, 2012 at 0:26

You must log in to answer this question.

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