+ Start a Discussion
Daniel Rudman 5Daniel Rudman 5 

Lookup field components

Are there UI components that handle lookup field selection, for example lookup from my custom object to an account? From experience this takes a lot of effort to implement and would seem like a very common use case. Maybe there is an open source version?

Simon ReparSimon Repar
Did you consider apex:inputfield tag? It has implemented logic for lookup fields.

Daniel Rudman 5Daniel Rudman 5
Thanks Simon, that is for VF, however I am looking for the equivalent for a Lightning component. Do you know if such a component exists?
Hi Daniel,
at the moment there is no standard component that does it and you have to code it your way...I believe that there will be some sort of "lightning" lokkup component in th enear future.
I have developed a lookup component in form of typeahead input (but unfortunately I cannot share the code :( ).
Daniel Rudman 5Daniel Rudman 5
Thanks Enreeco, appreciate the response. OK, I will follow up with our reps at Salesforce then and try to find out when that will become available. I know from experience that trying to recreate that is a monumental effort.
sfdcDeveloper 12sfdcDeveloper 12
Hi Daniel,

Did you got the solution for lookup field.
Amit GoyalAmit Goyal
Hi All,

Try this component provided by Enrico Murru, You will need to do some customization based on your requirement.
Even I am also applying this now. Feeling some complication to get the Id of the selected record.


Let me know if you get your solution by this to guide me too.

Amit Goyal
Enrico's solution works great!!

Recent salesforce updated it's static resource loading process ...I simply did few modification to avoid require component .

I am loading static resources as below :
<ltng:require scripts='/resource/Lgt_InputLookup/js/jquery-2.1.1.min.js,/resource/Lgt_InputLookup/js/bootstrap.min.js,/resource/Lgt_InputLookup/js/typeahead.js' afterScriptsLoaded="{!c.initTypeahead}" />

I removed requireJs dependecies in createTypeaheadComponent function and it's working..:-) 
createTypeaheadComponent: function(component){

        var self = this;
        var globalId = component.getGlobalId();
              var inputElement = $('[id="'+globalId+'_typeahead"]');

                //inits the typeahead
                    hint: false,
                    highlight: true,
                    minLength: 2
                    name: 'objects',
                    displayKey: 'value',
                    source: self.substringMatcher(component)
                //selects the element
                      function(evnt, suggestion){
                              component.set('v.value', suggestion.id);
                              component.set('v.nameValue', suggestion.value);