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.
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.
Attribution to: Daniel Ballinger
Possible Suggestion/Solution #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:
- Custom text field, mark as ExternalId for indexing purpose.
- UI control...probably would have to be custom visualforce + apex controller.
- Related Lists...again, custom visualforce + apex controller.
- Probably some other stuff I can't think of right now, but that would be the minimum as I envisage it.
Attribution to: pchittum
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/3450