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
Aurora Ganguly 10Aurora Ganguly 10 

visual force search functionality

Hi All,
I have a query , i made a vf page . and there i have provided a search buton with a text box, so i just want to expand the functionality like, suppose when i will type inside the search box any product name then it must show the available products from the custom product object based on from a particular category in the same vf page only , because in product object there is category section also , 
so how it can be achived in vf page to fetch from custom object , 
regards,
Aurora 
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Aurora Ganguly,

Please refer 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;
    }


   
}

I hope it will be helpful.

Please mark it as best answer if the information is informative.

Best Regards
Rahul Kumar

 
Aurora Ganguly 10Aurora Ganguly 10
thanks Thanks and regards, Aurora Ganguly