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
aressaress 

Visual force page for Account object

Can anyone help me in code for designing VF page with following functionalities.?

The account manager now wants the function to search for a particular account from the account list page.
Add a textbox to the top of the VF page that will take the account name. Add a button as well that will perform the search on the accounts and display the results accordingly. The count of the accounts should also be updated.
The search should also be performed on pressing the enter button on the keyboard. If nothing has been entered in the textbox, a message should be displayed stating that “Input at least 3 characters to perform search”.

The results of the search should be displayed without refreshing the page. Also add a link to clear the search results.
Dinesh GopalakrishnanDinesh Gopalakrishnan
Hi Ayisha,

I Hope the Below Code will Fit your Requirement.Let me Know if you face any Issues Regarding this.

/**************************************Apex Class****************************************/

public class FetchRecords
{
    public String InputBox{get;set;}
    public List<Account> AccountList{get;set;}
    public Integer AccSize{get;set;}
    public String MatchString;
    
    public void FetchRecordsMethod(){
        MatchString =  '%'+ InputBox +'%';
        AccountList = [SELECT Id,Name FROM Account WHERE Name LIKE :MatchString ];
        System.debug('***AccList' + AccountList );
        AccSize = AccountList.size();
    }
}

/**************************************Visual Forece Page****************************************/

<apex:page controller="FetchRecords" >
   <apex:form > 
     <script type='text/javascript'>
            function noenter(ev)  {
                if (window.event && window.event.keyCode == 13 || ev.which == 13) {
                    
                    KeyPressCall();
                    return false;
                 } else {
                      return true;
                 }
             }
        </script>
       <apex:pageBlock title="Pirate Account">
           <apex:pageBlockButtons location="bottom">
                       <apex:commandButton value="Search" action="{!FetchRecordsMethod}"/>
           </apex:pageBlockButtons>
           <apex:pageBlockSection columns="1">
                           <apex:actionFunction action="{!FetchRecordsMethod}" name="KeyPressCall"/>
                               
                                
                                <apex:inputText label="Search value" value="{!InputBox}" onkeypress="return noenter(event);"/>
            </apex:pageBlockSection>
            <apex:pageBlockSection title="Results" >
                <apex:pageBlockTable value="{!AccountList}" var="site" >
                    <apex:column value="{!site.Name}"/>
                 </apex:pageBlockTable>
            </apex:pageBlockSection>
       </apex:pageBlock> 
   </apex:form>
</apex:page>

Kindly Mark this as a Best Answer if you Find this Useful!

Thanks
DineshKumar Gopalakrishnan
Shivani Thakur 32Shivani Thakur 32
how we doing testing for this code?