+ Start a Discussion
Niraj Kr SinghNiraj Kr Singh 

How to create a "Related to" picklist lookup field

My requirement is to create a field like "Related to" in this image.
Step1: Picklist with the Objects
Step2: On select of any one object, need to display all related records
Requirement to create a field like "Related to" field in this picture
Give me quick suggestion.

Thakns Niraj  
Best Answer chosen by Niraj Kr Singh
Rahul SharmaRahul Sharma
You would need to create custom functionality if you want to achieve something like that.
Create a picklist fields with available object names in related to and create custom lookup as mentioned in Jeff's blog (http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/).
In the javascript function: baseURL(refer blog post page: MyCustomLookup), add a parameter to dynamically load the pass the object name to the new page.
// Following is the url of Custom Lookup page. You need to change that accordingly
baseURL = "/apex/CustomAccountLookup?txt=" + txtId + '&objectName=' + objectApiName;

Then read objectApiName in CustomAccountLookupController to dynamically fetch the records using dynamic SOQL and List<sObject>.

Hope it helps!