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
vamsi garapativamsi garapati 

how to fetch records whose name starts with input letter in visual force?

I am trying to fetch all student records whose name starts with the letter given by the user
ANUTEJANUTEJ (Salesforce Developers) 
Hi Vamshi,

I think the search function you can easily do it in trailhead for which the link is: https://trailhead.salesforce.com/en/content/learn/projects/develop-account-geolocation-app-with-aura-components/develop-account-geo-app-create-account-search-component

In case if you could something like:
 
<apex:page Controller="SearchInVFController">
    <apex:form>
        <apex:inputText value="{!searchKey}" label="Input"/>
        <apex:commandButton value="Search records" action="{!search}"/>
        <apex:commandButton value="Clear records" action="{!clear}"/>
        <apex:pageBlock title="Search Result">
            <apex:pageBlockTable value="{!acc}" var="a">
                <apex:column value="{!a.name}"/>
                <apex:column value="{!a.id}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
 
public class SearchInVFController {
    public list <Account> acc {get;set;}
    public String searchKey {get;set;}
    public SearchInVFController( ) {
    }
    public void search(){
        string searchquery='select Name,id from account where name like \'%'+searchKey+'%\' Limit 10';
        acc= Database.query(searchquery);
    }
    public void clear(){
        acc.clear();
    }
}

I hope this helps.

Anutej