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
Daniel Rudman 5Daniel Rudman 5 

Lookup field components

Hi,
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?

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

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_inputField.htm
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?
EnreecoEnreeco
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.

https://developer.salesforce.com/blogs/developer-relations/2015/06/salesforce-lightning-inputlookup-missing-component.html

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

Thanks,
Amit Goyal
DEBADYUTI SIL 30DEBADYUTI SIL 30
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
                inputElement.typeahead({
                    hint: false,
                    highlight: true,
                    minLength: 2
                },
                {
                    name: 'objects',
                    displayKey: 'value',
                    source: self.substringMatcher(component)
                })
                //selects the element
                .bind('typeahead:selected', 
                      function(evnt, suggestion){
                          $A.run(function(){
                              component.set('v.value', suggestion.id);
                              component.set('v.nameValue', suggestion.value);
                          });
                      });
       
    }