+ Start a Discussion
Mayank Deshpande 2Mayank Deshpande 2 

Hi All, I am new in sales force. My requirement is like i want to search Contacts based on Last Name.

I Create a VF page with below Code 

apex:page Controller="ContactNomineeController" showHeader="True">
<apex:image value="{!$Resource.Contact}" width="500" height="100"/>
<apex:form >
            <apex:actionFunction action="{doquery}" name="QueryContact" reRender="MyContact"/>
            <div class="filterDiv">
            <label>Filter By Last Name:</label>
                       <apex:inputText value="{!serachstring}"  onkeyup="apexDoQuery()"/>
 <apex:pageBlock title="Search Contact" id="MyContact">
 <apex:pageBlockButtons >
 <apex:commandButton value="save" action="{!save}"/> 
 <apex:pageBlockTable value="{!ConList}" var="Con">
<apex:column value="{!Con.Name}"/>
  <apex:column value="{!Con.accountid}"/>
<apex:column headerValue="Email"> 
   <apex:inputField value="{!Con.email}" />
 <apex:column value="{!Con.phone}"/> 
  <apex:column headerValue="Nominee"> 
   <apex:inputCheckbox value="{!Con.Nominee__c}" />

and Controller Class 

public with sharing class ContactNomineeController {
 Public List<Contact> ConList {get;set;}
 Public List<Contact> Contacts {get;set;}
 Public String serachstring {get;set;}
 Public ContactNomineeController (){
  Public void doquery(){
 String querystring='';
 if (serachstring!= null)
 querystring = '%' +serachstring+ '%';
 ConList= [select id,accountid,name,email,phone,Nominee__C from Contact where lastname like :querystring LIMIT 10 ];
 Public void save() {
 update ConList; }

Code saved but not able to search contact.
Need help to understand the loophole.

Try the below code.It works for me
VF Page Code:

<apex:page controller="SearchContact_AC">
        <apex:messages />
            Enter LastName:<apex:inputText value="{!Searchkey}"/>
            <apex:commandButton value="Search" action="{!Search}"/>
            <apex:pageBlockTable value="{!cntlist}" var="cnt">
                <apex:column value="{!cnt.Name}"/>
                <apex:column value="{!cnt.AccountId}"/>
                <apex:column value="{!cnt.Email}"/>
                <apex:column value="{!cnt.Phone}"/>

Controller Code:
public class SearchContact_AC 
    public String Searchkey{get;set;}
    public List<Contact> cntlist{get;set;}
    public void Search()
        cntlist=[select Name,AccountId,Email,Phone from Contact where LastName=:SearchKey];
            ApexPages.addMessage(new ApexPages.message(ApexPages.Severity.WARNING,'No Record Found'));

Hope it will satistify your requirement

Mayank Deshpande 2Mayank Deshpande 2
Hi Vignesh
 but i tried to search the contact using apex:action function and for that i define do query method . but it only refersh the page. how can we solve this.