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

how to perform search operation ?

 Hai every one.....


           I am new to sfdc......  I had one visualforce page with the following:-


                                        Location  |______________|  


                               Expected sal      |______________|



                                      Skill set       |______________|



                                    Experience   |______________|


                                                                            |      SEARCH |   


                        I had one position object  (custom) . i would like to perform search on  Location(us,uk) and expected sal (less than 2L,3L or >=6L etc) and Skill set(java,.net... etc) Experience(<2yrs,or >3yrs etc....) .

If user enter  any values in visual force page and clicks search button then we need to display the records belonging to his criteria .

But  iam unable to perform search on all Fields ....

i created one query but it is quering only with one field ineed to have with all fields.... can any one help me.....

provide any code snippet...

public with sharing class ItemEditController {

    private ApexPages.StandardController controller {get; set;}
  public List<applicant__c> searchResults {get;set;}
   public List<position__c> searchResult {get;set;}
  public string searchText {get;set;}
   public string searchwith {get;set;}
  // standard controller - could also just use custom controller
  public ItemEditController(ApexPages.StandardController controller) { }
  // fired when the search button is clicked
  public PageReference search() {
String qry = 'select First_Name__C,Last_Name__c, mobile__c,Skill_set__c,Experience__C,Expected_Annual_Salary__C,current_salary__C from applicant__c ' +
      'where First_Name__C LIKE \'%'+searchText+'%\' ';
    searchResults = Database.query(qry);
   return null;
    return Page.SearchApplicants;
  // fired when the save records button is clicked
  public PageReference save() {
    try {
      update searchResults;
    } Catch (DMLException e) {
      return null;
    return new PageReference('/'+ApexPages.currentPage().getParameters().get('id'));
  // takes user back to main record
  public PageReference cancel() {
    return new PageReference('/'+ApexPages.currentPage().getParameters().get('id'));



I think what you want to check out is Salesforces Object Search Languge (SOSL), instead of SOQL. Check out this article from their documentation

Shailesh DeshpandeShailesh Deshpande
Why are you using first name? If you have to search based on location, you should use the field corresponding to location in your object. Similarly, if you have to perform search based on experience, you should use the experience field in your object.

I assume you are using inputText fields to get the inputs from the page

So your code on the page must be something like:

Location: <apex:inputText value = {!LocationSearchText}/>
Experience: <apex:inputText value={!expSearchText}/>

where LocationSearchText and expSearchText are the variables declared in controller.

So your query should be something like:

string strLocationSearchText = '%" + LocationSearchText + '%';
Integer intexpSearchText = expSearchText;

select (all the fields that you want) from position__c where location__c like :strlocationsearchText and experience__c =: intexpSearchText



You can do like this:

string strQuery='select First_Name__C,Last_Name__c, mobile__c,Skill_set__c,Experience__C,Expected_Annual_Salary__C,current_salary__C from applicant__c';

if(Location!=null || Expected sal !=null || Skill set !=null || Experience!=null)


  strQuery=strQuery+' Where';


if(Location!=null && Location!='')


    strQuery = strQuery +'Location__c=+Location+ and';


f(Skill set!=null && Skill set!='')


    strQuery = strQuery +'Skill set__c=+Skill set+ and';


f(Expected!=null && Expected!='')


    strQuery = strQuery +'Expected__c=+Expected+ and';


strquery = strquery.substring(0,index('and')-1);





 hai sailesh....


This is my visualforce page code:-


<apex:page standardController="Applicant__c" extensions="ItemEditController" sidebar="false">
  <apex:sectionHeader title="{!Applicant__c.Name}" subtitle="Applicant Records"/>
    <apex:form >
      <apex:pageBlock mode="edit" id="block">
        <apex:pageBlockButtons location="bottom">
           <apex:commandButton value="Save Records"/>
             <apex:pageMessages />
      <apex:pageBlockSection >
        <apex:pageBlockSectionItem >
          <apex:outputLabel for="searchText">Keywords</apex:outputLabel>
            <apex:panelGroup >
              <apex:inputText id="searchText" value="{!searchText}"/>
                <apex:commandButton value="Search" action="{!search}" rerender="block" status="status"/>
         <!--   <apex:pageBlockSectionItem >
              <apex:outputLabel for="searchText">Skillset</apex:outputLabel>
                <apex:inputText id="searchText" value="{!searchText}"/>
         <apex:pageBlockSectionItem >
              <apex:outputLabel for="searchText">Experience</apex:outputLabel>
                <apex:inputText id="searchText" value="{!searchText}"/>
               <apex:pageBlockSectionItem >
                   <apex:outputLabel for="searchText">Expected Salary</apex:outputLabel>
                   <apex:inputText id="searchText" value="{!searchText}"/>
        <!-- <apex:commandButton value="Search" action="{!search}" rerender="block" status="status"/>&nbsp;&nbsp;-->



from the above code i got four input fields when enter any value regarding experience cosidering 2yrs  if i enter 2 in the experience field then records with experience 2 need to be displayed.


how i need to write the code in controller and visualforce..........

  if u have any  SOSL or SOQL code for that can u share with me

Shailesh DeshpandeShailesh Deshpande
You are using the "searchText" property for all the inputs. You should use 4 different properties for each of the input. For eg. In my previous post I have mentioned LocationSearchText for location and expSearchText for experience field. You need to do it in that way. Then use those fields in your SOQL query.