function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Manu SrivastavaManu Srivastava 

lookup against multiple record types for a custom object

Is there a way to add a lookup relationship to a custom field on a custom object which allows me to select one of many objects to define the relationship.

The need:

I am developing a managed app which I plan to list on the app exchange. 

As part of this solution, I have a custom object which could be related to account, opportunity, contacts (and other standard or custom objects by extension).

Currently, I have three custom lookup fields defined on my custom object, one for each of account, opportunity and contact.

If there a way where I could have one field, maybe I call it related_object and store the ID of that object as well as the type or name (is it an account, opportunity, contact, or any other xyz standard or custom object).

That way, if in a particular deployment, the org has a custom account object for example, my custom object can still be associated with it by giving the ID and name. 

In absense of this, I will have to customize my custom object for each org that I sell my app to.

Any help, direction, pointers will be appreciated.
VineetKumarVineetKumar
You may not be able to use a lookup field if you want to make it dynamically, as lookup field type are tighty associated to the sObject type, which you define while creating the field.
Perhaps you can create few custom text field, containing Id, object type.
Not sure what your actual requirement is, maybe it would have some better alternative.