Tell me more ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

share|improve this question

1 Answer

up vote 4 down vote accepted

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.
share|improve this answer
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. – Daniel Ballinger Oct 18 '12 at 0:15
Thanks for adding the link. Will look at it and likely vote it up! – Peter Oct 18 '12 at 0:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.