+ Start a Discussion

How to create lookup field having multiple objects.

I want to create a lookup field which can select from different type of objects.


For example, in Tasks,  related to field has following datatype.


Lookup(Contract,Product,Asset,Campaign,Account,Opportunity,Case,Solution,Position,Candidate,Job Application,Review,Employment Website,Job Posting,Mileage)



how to create Lookup field with composite datatype as above? I think its not possible with point and

click solution for creating field? i need to do it using visualforce/apex?



Best Answer chosen by Admin (Salesforce Developers) 

Tasks is unique at SFDC in the polymorphic WhoId field.  There isn't a custom field type that duplicates this as sharing gets really hard to calculate (slow for you).


You might want to do something closer to campaign member which has separate lookup fields for every type of object possible.  Then you can use a VF page to fake the polymorphic ID by having a "Type" picklist, which if changed would cause a partial page refresh changing which lookup field is displayed.


If Type = Contact, refresh & display the Contact__c field.  If Type = Lead, refresh & display the Lead__c field.