+ Start a Discussion
SFDC New learnerSFDC New learner 

Need help with autosuggest in the input text field

Hi All,

I have a user object with a username field. When I try to enter a letter, it should show all the values that start with that letter.

Say, for example, If I enter a letter J, it should display all the names that start with J like John, Jeff and so on.

How to implement this functionality using vf page?

Thanks,
Sirisha
Khan AnasKhan Anas (Salesforce Developers) 
Hi Sirisha,

Greetings to you!

Below is the sample code which I have tested in my org and it is working fine. Kindly modify the code as per your requirement.

Visualforce:
<apex:page Controller="AutoSuggestC" docType="html-5.0">
    <apex:form>
        <apex:pageBlock>
            Enter Account Name : <apex:inputText list="{!listOfStrings}"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Controller:
public class AutoSuggestC {
    
    public List<String> listOfStrings {get; set;}
    
    public AutoSuggestC() {
        listOfStrings = new List<String>();
        for(Account a: [SELECT id, Name From Account LIMIT 10])
            listOfStrings.add(a.name);
    }
}

This feature works only when the docType of VF page is set to “html-5.0”.

Please refer to the below links which might help you further with the above requirement.

http://www.infallibletechie.com/2012/06/auto-complete-text-box-in-salesforce.html

http://anupjadhav.com/2013/02/01/jquery-autocomplete/

https://www.jitendrazaa.com/blog/salesforce/ajax-based-autocomplete-component-in-salesforce-using-jquery-ui-and-json/

http://salesforcecodes.blogspot.com/2015/08/how-to-build-autocomplete-fields-in.html

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas