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
m pandeym pandey 

search records

i have created class and vf page on contact object...
in vf page when ever i search in search field of vf page then all records related to the contact should be the result..?
if i type 'ab' and search the ab related or the name it self contain ab alphabets or word should be displayed in vf page.?
​how can we achieve...?
Best Answer chosen by m pandey
vishnu Rvishnu R
Hi Gopal,
 
public class accsearchclass {
    public  string searchvalue{set;get;}
    public List<Account> acc = new List<Account>() ;
    public List<Account> accd= new List<Account>() ;
    public july1taskclass(){
        if(searchvalue==null){
            acc=[select Name,AccountNumber,Phone from Account];
        }       
    }    
    public string getsearchvalue() {
        return searchvalue;
    }  
    public List<Account> getacc(){
        return acc;
    }
    public void doSearch() {
        String Qry= '%'+searchvalue+'%';
        acc=[select Name,AccountNumber,Phone from Account where Name Like :Qry];
    } 
}

vf page:
 
<apex:page Controller="accsearchclass" >
    <apex:form >
        <apex:pageBlock title="Search Accounts By Name" id="block" >
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:inputText value="{!searchvalue}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:commandButton value="search" action="{!doSearch}" status="status"  reRender="block" />
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockTable var="a" value="{!acc}" rendered="{!NOT(ISNULL(acc))}" >
                <apex:column value="{!a.Name}" />
                <apex:column value="{!a.Phone}" />
                <apex:column value="{!a.AccountNumber}" />
            </apex:pageBlockTable>            
        </apex:pageBlock>
    </apex:form>
</apex:page>
mark this as best answer if it resolve your issue..:-)
Thanks 
Vishnu R

All Answers

Rowallim TechnologyRowallim Technology
Hi M pandey
you can acheive this by using query(select id, name from Contact where name LIKE 'ab').
Thnx
vishnu Rvishnu R
Hi Gopal,
 
public class accsearchclass {
    public  string searchvalue{set;get;}
    public List<Account> acc = new List<Account>() ;
    public List<Account> accd= new List<Account>() ;
    public july1taskclass(){
        if(searchvalue==null){
            acc=[select Name,AccountNumber,Phone from Account];
        }       
    }    
    public string getsearchvalue() {
        return searchvalue;
    }  
    public List<Account> getacc(){
        return acc;
    }
    public void doSearch() {
        String Qry= '%'+searchvalue+'%';
        acc=[select Name,AccountNumber,Phone from Account where Name Like :Qry];
    } 
}

vf page:
 
<apex:page Controller="accsearchclass" >
    <apex:form >
        <apex:pageBlock title="Search Accounts By Name" id="block" >
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:inputText value="{!searchvalue}" />
                </apex:pageBlockSectionItem>
                <apex:pageBlockSectionItem >
                    <apex:commandButton value="search" action="{!doSearch}" status="status"  reRender="block" />
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>
            <apex:pageBlockTable var="a" value="{!acc}" rendered="{!NOT(ISNULL(acc))}" >
                <apex:column value="{!a.Name}" />
                <apex:column value="{!a.Phone}" />
                <apex:column value="{!a.AccountNumber}" />
            </apex:pageBlockTable>            
        </apex:pageBlock>
    </apex:form>
</apex:page>
mark this as best answer if it resolve your issue..:-)
Thanks 
Vishnu R
This was selected as the best answer
m pandeym pandey
Thnk u so Much
m pandeym pandey
i also need to get edit delete options on each record.?