You need to sign in to do that
Don't have an account?
Isaac Gomolka
How to search for User information
Hi. I was wondering how/ whats the best way to do this: I need like an inputfield box or something on my Visualforce page where someone can type in a User ( preferably the Name like "Matt Smith", but could also be username or nickname or something). And that then makes sure that there is a user by that name in the Salesforce sandbox so that I can see that searched for User's information. I need this because I need to make something that will take that User the person searched for, and create a new User cloning that looked up user's profile, permission sets, etc(more detailed, but not important). So i need a way to search for a user and then be able to pull information from that user to use later when making a new User. Im sorry if this is stupid or confusing, I'm still new to Salesforce and could really use some help. Please and thank you soooo much!
"my Visualforce page where someone can type in a User ( preferably the Name like "Matt Smith", but could also be username or nickname or something)."
That is not standard in Salesforce so you need a new custom component instead of the standard inputfield component (with a dynamic behavior using jQuery).
Visualforce Autocomplete For Lookup Fields: inspired by Jitendra Zaa and his fantastic blog post below.
https://opfocus.com/visualforce-autocomplete-lookup-fields/
AutoComplete Component in Visualforce using JQueryUI
http://www.jitendrazaa.com/blog/salesforce/ajax-based-autocomplete-component-in-salesforce-using-jquery-ui-and-json/
Based on the technique of jQuery Autocomplete: Enables users to quickly find and select from a pre-populated list of values as they type, leveraging searching and filtering. https://jqueryui.com/autocomplete/
That is not trivial at all and quite complicated to do.
"you type in the name and click a button and it says wether he is a user or not, or something of the sort.":
That is a common technique when you need to control a remote name with a webservice in a referential base indeed but for user names in your Salesforce org (some hundreds people until some thousands max) you can have the autocomplete search effectively and that will blow your client away.
Autocomplete is also useless indeed if you just want to verify the existence of a complete name that you type in very precisely each time and the search of duplicate can be very complicated as soon as it is not the exact values that you compare.
For the duplicates : Matching Algorithms: Used with Matching Methods in Salesforce:
https://help.salesforce.com/articleView?id=matching_rules_matching_algorithms.htm&type=5&lang=en
The results can be a little disturbing for the first names in particular with SOSL (Bob and Robert will be find and return).
SOSL: WITH SPELL_CORRECTION is an optional clause that can be added to a SOSL query. When set to true, spell correction is enabled for searches that support spell correction. When set to false, spell correction is not enabled. The default value is true. The WITH SPELL_CORRECTION clause can be used in API version 40 or later. Example: The following SOSL statement disables spell correction on a search of accounts for the term San Francisco. FIND {San Francisco} IN ALL FIELDS RETURNING Account WITH SPELL_CORRECTION = false
https://resources.docs.salesforce.com/sfdc/pdf/salesforce_soql_sosl.pdf
SOQL: easy and sufficient with just LIKE : The LIKE operator performs a case-insensitive match, unlike the case-sensitive matching in SQL.
Autocomplete + underlying SOSL WITH SPELL_CORRECTION : that will blow your client away.
Search Spelling Correction overview: Let's use the example of searching for 'John deo'. The results returned would include 'John Doe' and various other matches
https://help.salesforce.com/articleView?id=000269438&language=en_US&type=1
in principle, that there is much further to go but you can just create a basic SOQL request like:
SELECT FirstName , LastName FROM user WHERE LastName like '%myString%'