+ Start a Discussion
Rafael Suarez 13Rafael Suarez 13 

Searching for records on the Master object at the other side of a Junction object

We sort of need Opportunity Products, but we don't need the complications that the Pricebooks present.  
So I've created a "Junction_obj" between Opportunity and "Master_Obj".  This object at the custom side of the Many to Many relationship contains a series of fields we want to show within a Related list in Opportunities.  

I added the Junction_obj as a Opportunity related list.  I set it to show 5  Master_Obj values.
User-added image

Clicking my 'New Opportunity Junction record'  button will show a "Junction_obj Editpage", with 3 fields:
Opportunity__c lookup (pre populated)
Junction_Obj Master-Detail(Custom_Obj) lookup
Quantity_c number (blank) 
User-added image
As the Master_Obj lookup is blank, we need to click the looking glass icon to search for Master_Obj field values to relate to the new Junction_Obj record. However, only Master_Obj.NAME {labeled MASTERID in the list} values are searchable. EG the autonumbered "CC0075" Master record Name.

Typing existing values of any other fields will fail a search.
User-added image
As a stopgap, I added a detail page button that lets users search all Master_Obj records for any values, and then copy the Name value and paste in the lookup.  It's an ugly solution with 3 redundant  steps per related list record.

I'm thinking of writing a VF with a controller class powered by SOQL that will search Master_Obj fields, and allows the selection of a record, whose ID will be set as the master of the new Junction_Obj detail record.  But this strikes me as too convoluted.  

Anyone have a better idea on how to allow the searches?

Thanks in advance.