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
Ivan sklyarov 2Ivan sklyarov 2 

how to create custom contact search

I need to get something like

User-added image
on my visualforce page.

how can I create such component ?

Ajay K DubediAjay K Dubedi
Hi Ivan,
Please check this sample code:
Controller:
public with sharing class consearchcontroller { 
public list <contact> con{get;set;} 
public string searchstring {get;set;} 
public consearchcontroller( ) { 
} 
public void search(){ 
string searchquery='select lastname,id from contact where lastname like \'%'+searchstring+'%\' Limit 20'; 
con= Database.query(searchquery); 
} 
public void clear(){ 
con.clear(); 
} 
}
Visualforce Page:
<apex:page Controller="consearchcontroller" > 
<apex:form > 
<apex:inputText value="{!searchstring}" label="Input"/> 
<apex:commandButton value="Search records" action="{!search}"/> 
<apex:commandButton value="Clear records" action="{!clear}"/> 
<apex:pageBlock title="Search Result"> 
<apex:pageblockTable value="{!con}" var="c"> 
<apex:column value="{!c.name}"/> 
<apex:column value="{!c.id}"/> 
</apex:pageBlockTable> 
</apex:pageBlock> 
</apex:form> 
</apex:page>

Thanks
Ajay