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
Mike @ BlackTabMike @ BlackTab 

Object That Can Be Related To (Almost) Any Other Object

Hello,

 

I'm in the process of creating a todo manager. I need a way to relate a todo to almost any object (like an activity). What's the best way to do that?

 

I'm interested in hearing some solutions. Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Salesforce WizardSalesforce Wizard

I don't think salesforce suports customized Polymorphic fields (Like the related to field on an activity).

 

The only way I can think of doing this is to have a lookup field for every object you have. you might want to add a final field that always is populated with the name or ID of whatever record got used so you can report on a single field.Then use Visualforce to make it look like it's a single lookup field.

 

That's the only way I can think of doing it if you want to have the records be displayed as a related list on any of the tables. 

 

Well, there is one other method you can try.

 

Instead of using a look up field, have two fields, one for the ID of the "lookup record" and the second for the name of that record.

 

You'll need to use visualforce to control the population of that data if you want to make it slick and easy for your end-users.

 

Then you have some options.

 

1. Create a link on every object that would be using it that passes the ID of the record to the report. You report will list all your custom object where pv0="RecordID" That will give you a list of all your "ToDos" with a lookup of that record. 

 

2. Create a visualforce page that is inline with all the major Sobjets that'll be using it. This page would query for all the "ToDo" records using the current record as it's look up value

 

3. Overwrite the whole page so you can have your own custom related list. You do the same thing as option 2, but it appears as a regular related list.

 

Personally, I think options 1 and 2 are the better options. I lean towards 1 simply because you could do that very quickly without creating a lot of custom visualforce pages or overriding the standard layout.

 

 

All Answers

Salesforce WizardSalesforce Wizard

I don't think salesforce suports customized Polymorphic fields (Like the related to field on an activity).

 

The only way I can think of doing this is to have a lookup field for every object you have. you might want to add a final field that always is populated with the name or ID of whatever record got used so you can report on a single field.Then use Visualforce to make it look like it's a single lookup field.

 

That's the only way I can think of doing it if you want to have the records be displayed as a related list on any of the tables. 

 

Well, there is one other method you can try.

 

Instead of using a look up field, have two fields, one for the ID of the "lookup record" and the second for the name of that record.

 

You'll need to use visualforce to control the population of that data if you want to make it slick and easy for your end-users.

 

Then you have some options.

 

1. Create a link on every object that would be using it that passes the ID of the record to the report. You report will list all your custom object where pv0="RecordID" That will give you a list of all your "ToDos" with a lookup of that record. 

 

2. Create a visualforce page that is inline with all the major Sobjets that'll be using it. This page would query for all the "ToDo" records using the current record as it's look up value

 

3. Overwrite the whole page so you can have your own custom related list. You do the same thing as option 2, but it appears as a regular related list.

 

Personally, I think options 1 and 2 are the better options. I lean towards 1 simply because you could do that very quickly without creating a lot of custom visualforce pages or overriding the standard layout.

 

 

This was selected as the best answer
Mike @ BlackTabMike @ BlackTab

I was going to create a picklist of all the objects, then use a jquery autocomplete textbox that would dynamically lookup records based on whatever object is in the picklist. 

 

Thanks for the ideas, I'll do some experimentation and let you know which one works best.