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
sfdc_beginner7sfdc_beginner7 

Autocomplete and search funcationality

I have a below requirement  ,Need to create a custom object "Custom A"  which will have 2 look fields Account Name and Contact Name
.I need to create a vf page such that if I click on account name it shows me 10 records and a search box that
let me search account by putting 3 alphabets and same funcationality in contact name but it should search contact only related  to selected
account.

I have created a basic code .
Apex class
public class create_employee_mv {
    public List<String> listofAccountName {get;set;}
    public List<String> listofContactFirstName {get;set;}
    public Set<Id> AccId;
    public create_employee_mv(ApexPages.StandardController stdcntrl)
    {
        listofAccountName = new List<String>();
        Accid = new Set<Id>();
        for(Account a : [Select Id, Name,(select Employee_Designation__c from Employee_MVs__r)
                         from Account])
        {
         listofAccountName.add(a.name);
         Accid.add(a.id);
        }
        
        
    }

}

VF page
<apex:page standardController="Employee_MV__c" extensions="create_employee_mv" docType="html-5.0">
    <apex:form>
        
        <apex:inputText list="{!listofAccountName}"  /> &nbsp;
        <apex:inputField value="{!Contact_Name__c}"/>
        
    </apex:form>
</apex:page>



 
James LoghryJames Loghry
Hi there, if you google for Visualforce autocomplete, you'll find several examples, including this one that should suit your needs: https://opfocus.com/visualforce-autocomplete-lookup-fields/

Generally speaking, you'll need to use javascript within your VF page to handle the auto complete portion.  Everything else is pretty straight forward.

If you're requirement doesn't necessarily have to be Visualforce, you could also look at doing this with a Lightning Component, which is more Javascript-centric.  There are also a few examples on google of Lightning Component auto complete examples, including this one: http://www.lightningstrike.io/#!/strikeLookup.  Now, the strike example doesn't fit your criteria exactly, so you'd need to download the code from github and futz with it a little bit.

Good luck, and have fun :)
- James
sfdc_beginner7sfdc_beginner7
James ,since I am new to coding ,I tried this but not able to undertsand..is there any other way ?