0

I need to keep an input text where , when someone writes text (say initial 'a') all User's name in salesforce starting with the initial will come in drop down. Currently my code showing only logged in User Name and when try to write some other name it simply getting autodeleted. Please find my Page script here.

Page Script

 <apex:pageBlock id="pb" rendered="{!if((userType != 'Rep' || userType != 'Online Rep') ,true,false)}"> 
        <apex:pageBlockSection id="pbs1">
            <apex:pageBlockSectionItem id="pbsItem1">
                <apex:outputLabel >From User </apex:outputLabel>
                <apex:outputPanel >                                        
                    <input id="fromuser" value="{!fromUserName}" /> 
                    <apex:inputHidden value="{!fromUserName}" id="fromuser-nameHid"/>                
                </apex:outputPanel>
            </apex:pageBlockSectionItem>

            <apex:pageBlockSectionItem id="pbsItem2">
                <apex:inputHidden value="{!fromUser}" id="fromuser-id"/>
                <pre style="font-family:sans-serif" id="fromuser-description"></pre>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>

Here fromuser is current User but I require to change it and do any User whose name matches with input string.

Apex Class

 curUser = [Select Id,Name,IsActive from User where Id = :UserInfo.GetUserId()];
        fromUser = curUser.id;
        fromUserName= curUser.Name;
2

1 Answer 1

1

You can achieve this like below :

  • You need to trigger event every time a user enters any text in text box.
  • This event will take the input text to class and you will call a method which will call below method to search users by matching inout text :

    public static List<Users> getUsers(String query){ query = '%' + query + '%'; return [SELECT Id,Name FROM User WHERE Name LIKE :query]; }

You then show these users in the autocomplete.

If you want to know more about how to trigger event or create autocomplete please ask me.

2
  • Please elaborate I am not getting it clear. Please let me know exact methods or changes to be done in my code. Feb 12, 2016 at 7:26
  • Please let me know way to trigger the event. Feb 12, 2016 at 7:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .