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

Modify lookup field dialog to search on alternate fields

I have an application with a transaction record that has a lookup field to an employee object.  The name field in the employee object is the employee id.  We'd like to create our own lookup search page that allows the user to enter the employee name instead of the id.  This is similar to the filter functionality only it would be the initial search.  We know how to customize the lookup page but we would like to add a button, similar to the lookup icon, to the edit page to invoke our custom code.  Unlike display pages, it does not appear that you can embed a piece of Visualforce code on an edit page.  Do we really have to recreate the entire edit page in Visualforce or are we missing something?



I think you can use javascript to invoke your lookup page. Instead of going for a custom button you can use the

lookup field itself.


 try { window.sfdcPage.appendToOnloadQueue(initForm);} catch(e) {}
function initForm() {
overrideLookup("javascript: openLookup('/apex/AccountLookup?type=BillTo&lkfm={!$Component.form_order}&lknm={!$Component.form_order:order_header:order_info:section:account}&lktp=' + getElementByIdCS('{!$Component.form_order:order_header:order_info:section:account}_lktp').value,670,'1','&type=BillTo&oid={!id}&lksrch=' + escapeUTF(getElementByIdCS('{!$Component.form_order:order_header:order_info:section:account}').value))","{!$Component.form_order:order_header:order_info:section:account}_lkwgt");

The ids given in this function is the id of the lookup field.


function overrideLookup(href,id) {
var elLookup = getElementByIdCS(id);
if (elLookup != null) {
elLookup.href = href;



I'm also trying to build my own OpenLookup-Logic (apex-code and page) so it seems the orignial posting is exactly the question i am looking for. My goal is to replace the standard lookup functionality on custom apex-pages and standard page-layouts.


So I'm really happy to see, that someone else is looking for the same solution.


My question is: where do i place your code? There seems to be no place to put any javascript-code in standard page layouts.


Any tips? Or is this only possible in custom apex-pages?


Thx in advance




André Peters

Mike CaoMike Cao


    You can put your standard page into a iframe ,and then ,you can do whatever you want with the id of component.