0

I have implemented a searchable drop-down using jquery and visual force. Whenever I start typing a string it will search the database and bring all the matched users.

I am using a jquery to call a method in my controller and search the database using this string, then returning the results back to jquery where I'm displaying the results in a drop-down bar.

But this is showing all the users including users who are not visible to me.

VisualForce:

<span class='slds-grid_align-center slds-size_1-of-4' >
      <apex:repeat value="{!conList2}" var="con" id="conRepeatId">

<apex:inputText label="Input" value="{!con.Name}"  id="conName"  onfocus="autocompleteonfocus('{!1}');" styleClass="conName{!1}"/>
      </apex:repeat>
</span>

Jquery Script:

<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/smoothness/jquery-ui.css" />
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script>

         <script>
        $j = jQuery.noConflict();
        function autocompleteonfocus(row){
            var selectedId = null;
            $j('input[id$=conName],input[id$=conId]').autocomplete({ 
                minLength: 2,
                delay: 500,
                source: function( request, response ) {

                    CalendarController.checkThisMethod(request.term, function(res, evt){
                        console.log(res);
                        var result = [];
                        res.forEach(function(record) {
                            result.push( { 
                                label: record.Name,
                                Name : record.Name,
                                Id : record.Id
                            });
                        });
                        response(result);
                    });


                },
                select: function(event, ui) { 
                    console.log(ui);
                    event.preventDefault();

                    $j(".conName"+row).val(ui.item.Name);
                    selectedId = ui.item.value;
                    selectedUserChanged(ui.item.Id);
                },


            });

        }


        </script> 

Controller:

global with sharing class CalendarController {
    public ApexPages.StandardController controller;

    public list<User> conList2 {get;set;} 
    public List<User> conListNew {get;set;} 
    public static list<User> checkName {get;set;} 

    public CalendarController(ApexPages.StandardController controller){

        conList2 = new list<user>(); // do i need to do this step
        User c = new User();// do i need to do this step
        conList2.add(c);// do i need to do this step
}

@RemoteAction
    public static list<User> checkThisMethod(String checkName){
        String appendPercentile = '%' + checkName + '%';

        List<user> conListNew = new List<user>();
        conListNew.addall([select id,name from user where name like :appendPercentile]);
        system.debug('conListNew Value is: '+conListNew);
        return conListNew;

    }
}
1
  • What do you mean by users not visible to you? In what context are they not visible? Aren't you the sys admin? Please edit your post to clarify. Commented Sep 20, 2018 at 20:11

1 Answer 1

2

Portal Users and Community Users are not shown in Global Search.

But when you search for them in Setup search they would be visible.

enter image description here

That being said, if you want to show only the users which are visible in global search , that means you are looking for internal users. Internal Users dont have an associated contact. So your SOQL will be

@RemoteAction
    public static list<User> checkThisMethod(String checkName){
        String appendPercentile = '%' + checkName + '%';

        List<user> conListNew = new List<user>();
        conListNew.addall([select id,name from user where name like :appendPercentile and ContactID=NULL]);
        system.debug('conListNew Value is: '+conListNew);
        return conListNew;

    }
}
2
  • Pranay: When I say users visible to me, I mean that people who are visible to me in the hierarchy. Not Internal users
    – New
    Commented Sep 20, 2018 at 17:59
  • Can you edit the question to add that? Its bit ambiguous. Commented Sep 20, 2018 at 18:02

You must log in to answer this question.

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