Filtering Values not just on Lookup Record Name Field but also on the other fields of your choice

Posted on

Did you ever encounter a situation where two objects related through a Lookup Relationship had the Name Field as a ID field which is just a Numeric Identifier and there were other fields which had values on which you want to search on to select the Lookup field Value?

The reason I am writing this blog is the exact same reason where we ended up getting such a requirement from the Client. What we had on the Lookup Object was a Name field which was a Numeric Value or it can just be a Auto Generator Number. The Lookup object itself consisted of a Long Text Area field which had the text data. The requirement was to have a search functionality on the Text Area Field and select the record from the filtered values to populate the Lookup Name (in this case the numeric value). This was understandable from the business point of view as there was no way that they can remember a Numeric value of a record to identify what they want on the standard lookup filter.

How did we go about achieving it?

We had recently made the Standard Edit Page of the Object which had the Lookup field as a custom page by using Field Sets. This gave the flexibility to try some thing more. What we planned to do was to have a Link right beside the lookup Icon, in this way giving the option of using the Standard Lookup Search if the user knew the ID value or the custom search to search on the Text Area that we are about to build. The approach was, when the user clicks on the custom link, a pop up comes up (done using JavaScript and Visualforce which behaves like the functionality on Firefox where the background gets greyed out and the pop up is enabled). Now we went one step a ahead and provided further more filters on the pop-up rather than just the Text Area. For example, Name(Text), Type(Picklist) and the Description (Text Area).

The user was allowed to enter the required filter conditions and hit the search button, which in turn rendered the results on the same pop-up. Onclick of the record of interest, the pop-up is closed and the Lookup Numeric ID was populated on the edit screen on the Lookup Field.