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
mdinatalemdinatale 

Visualforce page search like standard search

I created a debt object and i have it opening a visualforce page on new and edit. I have a master-detail record to another object called creditor. On the standard edit there was a little page with a hour glass you could press to popup a search. How would i do this in the visual force page. Any help would be appreciated. Ive been trying diffrent things but can't figure it out.

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

It's a mangnifying glass, not an hourglass (that's what I thought it looked like, too!). But, to answer your question, create a record in memory in your controller that has a lookup field to the object you'd like to lookup, and then bind it to an <apex:inputField>.

 

Example:

 

public class con {
    public contact c { get; set; }
    public con() {
        c = new contact();
    }
    public void search() {
        // c.accountid has the selected ID.
    }
}

 

<apex:page controller="con">
   <apex:form>
     <apex:pageblock>
       <apex:pageblocksection>
          <apex:inputfield value"{!c.accountid}"/>
       </apex:pageblocksection>
    </apex:pageblock>
   </apex:form>
</apex:page>

You can also "roll your own" lookup, but that's a bit more code (yet, more flexible).