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
anjin reddy 9anjin reddy 9 

Displaying records by using Search button

Hi folks,
  please folks help me out in this sceraniro 

  My requirement is to creating search button in visualforce page ,,if we search any records by using records name ,it has to  display that records details.
Thanks in advance,,,

Thanks
Anjin
Best Answer chosen by anjin reddy 9
Siddharth ManiSiddharth Mani

I dont understand what you are trying to say. If you want only the search text box and no buttons, you can use the "onkeyup" or something else in the <apex:inputText> tag. For eg. :

VF Page:

<apex:page controller="contactActivityHistory3">
<apex:form >
      <apex:pageBlock title="Filter">
    <!--      <apex:pageBlockButtons >
              <apex:commandButton value="Fetch" action="{!fetch}" reRender="pagination"/>
          </apex:pageBlockButtons> -->
          <apex:pageBlockSection >
              <apex:inputText value="{!status}" label="Status" onkeyup="{!Fetch}"/>
          </apex:pageBlockSection>
      </apex:pageBlock>
      <apex:pageBlock title="Activity History" id="pagination">
      <apex:pageBlockSection >
          <apex:pageBlockTable value="{!ListTasks}" var="tsk">
              <apex:column headerValue="Contact" value="{!tsk.WhoId}"/>
              <apex:column headerValue="Subject" value="{!tsk.Subject}" />
              <apex:column headerValue="Status" value="{!tsk.Status}"/>
              <apex:column headerValue="Modified Date" value="{!tsk.LastModifiedDate}"/>
          </apex:pageBlockTable>
      </apex:pageBlockSection>  
  </apex:pageBlock>
</apex:form>
</apex:page>
Controler:
public class contactActivityHistory3 {
    
    public Boolean fetchCalled{get;set;}
    public String taskList{get;set;}
    public String status{get;set;}
    public String subject{get;set;}
    
    public contactActivityHistory3() {
        fetchCalled = false;
    }
    
    public void getFetch() {
        taskList = 'SELECT WHOID, Subject, Status, LastModifiedDate FROM Task WHERE Status LIKE \'%'+status+'%\'';
        List<Task> tskList = Database.query(taskList);
        fetchCalled = true;
    }

    public Task[] getListTasks() {
                        List<Contact> cntct = [SELECT Id, Name FROM Contact];
                List<Id> contactIds = new List<Id>();
                for(Contact cn : cntct) {
                contactIds.add(cn.Id);
                }
                
        if (fetchCalled) {
                getfetch();
        }
        
        else {
                        taskList = 'select whoid,subject,status,LastModifiedDate from task where whoid in : contactIds order by LastModifiedDate desc';    
        }
        List<Task> tskList = Database.query(taskList);
                return tskList;            
    }
}
This will have only textbox for Status field (or any other field based on which you need to query the database! You have to change the query accordingly) and once you enter text and hit return ("Enter" key on Windows machine keyboards), it will query and return teh results.
 

All Answers

Siddharth ManiSiddharth Mani
Hi Anjin,
Did something similar here:
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000MHWbIAO
2 types of search functionalities based on whether you want to search the records already being displayed on the table, or whether you want to query the database for the same. Please go through and let me know if it helps!
anjin reddy 9anjin reddy 9
Hi Mani,
  Thanks for giving such valuble code.
 My requirement is that i need to display records details from the database..

Thanks in advance

Anjin
 
Siddharth ManiSiddharth Mani
In that case you will need a custom controller and page as is provided in the link I gave before. Check the second approach for a simple demo using only standard objects and fields. You can of course use the same technique for Custom Objects as well!
anjin reddy 9anjin reddy 9

Hi Mani ,
 I need to give the command lik is manually...
 2)i dont want give the fetch button... when we enter the name its has display related details

could you please give the for this

Thanks in Advance

Anjin

Siddharth ManiSiddharth Mani

I dont understand what you are trying to say. If you want only the search text box and no buttons, you can use the "onkeyup" or something else in the <apex:inputText> tag. For eg. :

VF Page:

<apex:page controller="contactActivityHistory3">
<apex:form >
      <apex:pageBlock title="Filter">
    <!--      <apex:pageBlockButtons >
              <apex:commandButton value="Fetch" action="{!fetch}" reRender="pagination"/>
          </apex:pageBlockButtons> -->
          <apex:pageBlockSection >
              <apex:inputText value="{!status}" label="Status" onkeyup="{!Fetch}"/>
          </apex:pageBlockSection>
      </apex:pageBlock>
      <apex:pageBlock title="Activity History" id="pagination">
      <apex:pageBlockSection >
          <apex:pageBlockTable value="{!ListTasks}" var="tsk">
              <apex:column headerValue="Contact" value="{!tsk.WhoId}"/>
              <apex:column headerValue="Subject" value="{!tsk.Subject}" />
              <apex:column headerValue="Status" value="{!tsk.Status}"/>
              <apex:column headerValue="Modified Date" value="{!tsk.LastModifiedDate}"/>
          </apex:pageBlockTable>
      </apex:pageBlockSection>  
  </apex:pageBlock>
</apex:form>
</apex:page>
Controler:
public class contactActivityHistory3 {
    
    public Boolean fetchCalled{get;set;}
    public String taskList{get;set;}
    public String status{get;set;}
    public String subject{get;set;}
    
    public contactActivityHistory3() {
        fetchCalled = false;
    }
    
    public void getFetch() {
        taskList = 'SELECT WHOID, Subject, Status, LastModifiedDate FROM Task WHERE Status LIKE \'%'+status+'%\'';
        List<Task> tskList = Database.query(taskList);
        fetchCalled = true;
    }

    public Task[] getListTasks() {
                        List<Contact> cntct = [SELECT Id, Name FROM Contact];
                List<Id> contactIds = new List<Id>();
                for(Contact cn : cntct) {
                contactIds.add(cn.Id);
                }
                
        if (fetchCalled) {
                getfetch();
        }
        
        else {
                        taskList = 'select whoid,subject,status,LastModifiedDate from task where whoid in : contactIds order by LastModifiedDate desc';    
        }
        List<Task> tskList = Database.query(taskList);
                return tskList;            
    }
}
This will have only textbox for Status field (or any other field based on which you need to query the database! You have to change the query accordingly) and once you enter text and hit return ("Enter" key on Windows machine keyboards), it will query and return teh results.
 
This was selected as the best answer
anjin reddy 9anjin reddy 9
Hi Mani
thanks for giving such valuable code .

One request is that after displaying records when enter the name,,has to display link button for aany of fields.

Please give ur contact no ,,based on that i lll contact u if dnt mind 

Thanks
Anjin
+919972205440