+ Start a Discussion
Bablu Kumar PanditBablu Kumar Pandit 

How to impliment search functionlity in vf page

for exapmle if user enter details in search box and click on search button then if any name realed to account are avilable then ll the details of that Account
how to i impiment guide me
AbhishekAbhishek (Salesforce Developers) 
Hi,

Please refer to the below code for reference on Search Functionality.

VisualForce Page:

<apex:page controller="Searchname">
  <apex:form >
  <apex:PageBlock >
  <apex:PageBlockSection >
  <apex:PageBlockSectionItem >
  <apex:outputLabel > Name</apex:outputLabel>
  <apex:inputText value="{!name}"/>
  </apex:PageBlockSectionItem>
  <apex:commandButton value="Go" action="{!executeSearch}"/>
  </apex:PageBlockSection>
  <apex:PageBlockTable var="act" value="{!mycar}"> 
  <apex:column value="{!act.name}"/>  
  <apex:column value="{!act.Price__c}"/>
  </apex:PageBlockTable>
  </apex:PageBlock>
  <apex:PageBlock >
  <!--apex:commandButton value="Edit" action="{!edit}"/-->
  </apex:PageBlock>
  </apex:form>
</apex:page>



Apex Class:


public with sharing class Searchname {
     public String name { get; set;}
    public list<car__c> mycar { get; set; }
    public boolean searched{get;set;}
    public searchname() {
    searched=false;
    string namestr=ApexPages.currentPage().getParameters().get('name');
    if(null!=namestr) {
    name=namestr;
    //executeSearch();
    }
    }
    public PageReference executeSearch() {
      searched=true;
    System.debug('name' +name);
    string searchstr=('%'+name+'%');
    System.debug(searchstr);
   // accounts= new List<Account>();
    mycar=[select id,Name,price__c from car__c where name Like:searchstr limit 20];
    System.debug(mycar);
        return null;
    }
   
}


For further reference, you can check the below blog,

https://salesforce.stackexchange.com/questions/241489/search-functionality-in-vf-page


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks.
Bablu Kumar PanditBablu Kumar Pandit
Hii Abhishekh ,

I already tried this links ,i want that when Any Recode avilabe In the Org Realted to Account name Then we want to display Recode Detail page of that Account