+ Start a Discussion
BhmBhm 

how to search and display record of account object in vf page

Hi

plz, any one can make sure that how can i search and display a single record as per name of the account object.and also display the records as per alphabets.

 

 

Thanks..

hitesh90hitesh90

Hi,

 

 

Here is the example to search Account Record and display it alphabatically.

 

Visualforce Page:

<apex:page controller="ctrlAccountSearch">
    <apex:form >
        <apex:inputtext value="{!strAccSearchString}"/>
        <apex:commandButton value="Search" action="{!SearchAccountRec}"/>        
        <apex:pageBlock rendered="{!If(lstAccount.size>0,true,false)}" title="Search Result">
            <apex:pageBlockTable value="{!lstAccount}" var="acc">
                <apex:column >
                    <apex:facet name="header">Name</apex:facet>
                    <apex:outputLink value="/{!acc.id}">{!acc.Name}</apex:outputLink>                            
                </apex:column>                     
            </apex:pageBlockTable>           
        </apex:pageBlock>
        <apex:pageBlock rendered="{!If(lstAccount.size==0 && isResultDisplay == true,true,false)}" title="Search Result">            
                <apex:outputLabel value="No Result Found"></apex:outputLabel>           
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

Apex Class:

public class ctrlAccountSearch{
    public string strAccSearchString {get; set;}
    public List<Account> lstAccount {get; set;}
    public boolean isResultDisplay {get; set;}
    
    //  constructor
    public ctrlAccountSearch(){
        lstAccount = new List<Account>();
        isResultDisplay = false;
    }
    
    //  Search Function
    public void SearchAccountRec(){
        isResultDisplay = true;
        string strLikeString = '%'+strAccSearchString+'%';
        string strSOQL = 'select id,Name from Account where name LIKE: strLikeString order by Name asc';
        lstAccount = database.query(strSOQL);
    }
}

 

 

 

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.

Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

ashwitha gaddam 7ashwitha gaddam 7
how to display account in vf page
 
ashwitha gaddam 7ashwitha gaddam 7
and apex class also