Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
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
6 answers
  1. Dec 19, 2015, 5:46 AM

    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.

     
  2. Dec 30, 2015, 9:47 AM
    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
  3. Dec 11, 2015, 10:21 AM
    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!
0/9000