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
Denise CrosbyDenise Crosby 

need idea for lightning component searching for account

Hello.
I am creating a lightning component to override the New Opportunity button. Stagename is excluded, as I populate that field with an Apex trigger. What is the most efficient way to search for the account? I have 85,000 accounts, so should I use a combo box.... I need an idea on what to use.  Right now, the user has to enter the AccountID to save. Thanks in advance! 

NewOpp.apxc
public class NewOpp {
    
    @AuraEnabled
    public static void saveOpp(Opportunity opp) {
        system.debug('opp:' + opp);

        insert opp;
        //return opp.id;
    }
}

NewOpp.cmp
<aura:component controller="NewOpp" implements="flexipage:availableForAllPageTypes,lightning:actionOverride" access="global" >
    <aura:attribute name="opps" type="Opportunity[]"/>

    
    <aura:attribute name="newOpp" type="Opportunity"
                    default="{ 'sobjectType': 'Opportunity',
                             'Name': '',
                             'AccountId': '',
                             'CloseDate': '',
                             'Amount': 0 }"/>
    
    <lightning:card iconName="standard:opportunity" title="New Opportunity">
        <form class="slds-form--stacked">         
            <lightning:input aura:id="oppform" label="Owner"
                             name="ownername"
                             value="{!v.newOpp.AccountId}"
                             required="true"/>
            
            <lightning:input aura:id="oppform" label="Opportunity Name"
                             name="oppname"
                             value="{!v.newOpp.Name}"
                             required="true"/>
            
            <lightning:input type="number" aura:id="oppform" label="Revenue"
                             name="revenue"
                             value="{!v.newOpp.Amount}"
                             required="true"/>
            
            <lightning:input type="date" aura:id="oppform" label="Estimated Close Date"
                             name="closedate"
                             value="{!v.newOpp.CloseDate}"
                             required="true"/>
            <lightning:button label="Save"
                          class="slds-m-top--medium"
                          variant="brand"
                          onclick="{!c.clickCreate}"/>

        </form>
    </lightning:card>
</aura:component>

NewOppController.js
({
    clickCreate: function(component, event, helper) {
        var validOpp = component.find('oppform').reduce(function (validSoFar, inputCmp) {
            // Displays error messages for invalid fields
            inputCmp.showHelpMessageIfInvalid();
            return validSoFar && inputCmp.get('v.validity').valid;
        }, true);
        // If we pass error checking, do some real work
        if(validOpp){
            // Create the new expense
            var newOpp = component.get("v.newOpp");
            console.log("Create opp: " + JSON.stringify(newOpp));
            helper.createOpp(component, newOpp);
        }
    }
})

NewOppHelper.js
({
    createOpp: function(component, opp) {
    var action = component.get("c.saveOpp");
    action.setParams({
        "opp": opp
    });
    action.setCallback(this, function(response){
        var state = response.getState();
        if (state === "SUCCESS") {
            var opps = component.get("v.opps");
            opps.push(response.getReturnValue());
            component.set("v.opps", opps);
          //  var urlOpp = $A.get("e.force:navigateToURL");
          //  urlOpp.setParams({
          //      "url": response.getReturnValue()
                
          //  });
          //  urlOpp.fire();
         
        }
    });
    $A.enqueueAction(action);
},

})

Thanks so much for your help!
 
Best Answer chosen by Denise Crosby
Alain CabonAlain Cabon
Denise,  

You know what... Victory!  or Strike! like we say in bowling

You will adore this component.

User-added image
INSTALLATION & DEPENDENCIES: I installed the following files (just clicking on the links here (copy/paste): 
http://www.lightningstrike.io/#!/strikeLookup


a)  The following dependencies must also be saved to the org in order for the component to function:
  1. aura/defaultTokens      // it is a special kind of file in Lex (little used)
  2. aura/strike_evt
  3. aura/strike_tooltip
  4. aura/strike_svg
  5. classes/strike_lookupController.cls
  6. classes/strike_lookupController.cls-meta.xml
  7. classes/strike_responseData.cls
  8. classes/strike_responseData.cls-meta.xml
  9. classes/strike_tst_lookupController.cls
  10. classes/strike_tst_lookupController.cls-meta.xml
  11. classes/strike_utilities.cls
  12. classes/strike_utilities.cls-meta.xml

http://www.lightningstrike.io/#!/strikeLookup


b)  appiphony/Strike-Components​
  1. strike_lookup.cmp    
  2. strike_lookup.css    
  3. strike_lookupController.js
  4. strike_lookupHelper.js
  5. strike_lookupRenderer.js
https://github.com/appiphony/Strike-Components/tree/master/aura/strike_lookup

Create a simple lightning app at the end + Preview: 
<aura:application extends="force:slds" >
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <div class="slds-form slds-form_stacked slds-m-around_xx-large">
        <c:strike_lookup   aura:id="mylookupid"
                         label="Account"
                         object="Account"
                         searchField="Name"
                         placeholder="Select an option"
                         iconName="standard:account"
                         subtitleField="Industry"
                         order="Name"
                         limit="5"
                         loadingMessage="Loading..."
                         errorMessage="Invalid input"
                         allowNewRecords="false"
                         showRecentRecords="true"/>     

        <lightning:button variant="brand" label="Submit" onclick="{! c.handleClick }" />

    </div>
</aura:application>

doInit for testing the prepopulated field and handleclick for getting the selected value :
 
({
	doInit : function(component, event, helper) {
         var accountid = '0010Y00000WeuZrQAJ';       
         component.find("mylookupid").set("v.value",accountid);        
	},
    handleClick: function (component, event, helper) {
		var accountid = component.find("mylookupid").get("v.value");
        alert("value:" + accountid);
	},
})

That worked. Strike!

Alain
 

All Answers

Dev_AryaDev_Arya
Hi Denise,

This is what you need :
https://developer.salesforce.com/blogs/developer-relations/2015/06/salesforce-lightning-inputlookup-missing-component.html

This blog from developer.salesforce, teaches how to create a loopup in lightning. If you have any doubts related to the code content, please feel free to ask.

Cheers n happy coding,
Dev
Alain CabonAlain Cabon
Hello Denise,

As @dev_arya mentioned, Salesforce almost provides ... nothing for the lookup fields.

There is the component<force:inputfield> but you cannot prepopulate it (almost unusable).

The only alternatives are the numerous open-source projects  like the "old" project above (2015, the first one).

There is also this one:  SF-Lightning-Lookup:  Note: This component was built with version 40.0 (Summer 17).
https://github.com/chaturvedijai/SF-Lightning-Lookup

More recent and seems easy to use.

Our French expert Philippe Ozil for all the Lex components seems to work on his own project:   https://github.com/pozil/sfdc-ui-lookup
 I asked him directly in Paris during the Lightning Now Tour and his lecture about the data service what is the best alternative for a lookup component in Lex (he just answers me "build your own one!"). But it is difficult to develop this kind of component and his component is still in progress even for an expert of Lex.

Alain
Alain CabonAlain Cabon
Jai Chaturvedi (Salesforce Technical Specialist)  has developped the SF-Lightning-Lookup component above so it is surely a good component.

Salesforce will provide the official <lighning:lookup> and <lightning:picklist> components in ... the future (end of the next year, perhaps)

Here is the roadmap:
https://help.salesforce.com/articleView?id=lightning_components_roadmap.htm&type=0
 
sfdcMonkey.comsfdcMonkey.com
hi  , 
Please check below link for your solution, it will may help you :​

http://www.sfdcmonkey.com/2017/07/17/re-usable-custom-lookup/ 

User-added image
i hope it helps you.
      Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
    thanks 
sfdcmonkey.com 
 
Alain CabonAlain Cabon
@piyush_soni, did you use or test this component?  I am currently testing them one by one and they are all different with often some (big) issues and we can just try to fix them before imagining them in production.

sfdcmonkey.com is an excellent blog but their code is short with some bugs like almost 100% of the short code for a lookup component.
The lookup component of sfdcmonkey.com uses a simple "soql like"  SF-Lightning-Lookup uses "soql + sosl" and the component below is huge.

Lookupcomponent of JungleForce (Bangalore) seems the bigger development.

https://github.com/jungleeforce/lookupcomponent

Three pages of lookup components: 28 repositories (many empty shells, only on github + all the blogs like sfdcmonkey.com​ and all the blogs of the MVPs): https://github.com/search?utf8=%E2%9C%93&q=salesforce+lookup&type=

None of these developments have pills for multi-selection for example like the "real" lookup component.
Alain CabonAlain Cabon
I am trying to use SF-Lightning-Lookup currently (not stable right now after the first copy/paste).

The big problem when you use this complicated open-source code is:

1) short and buggy.
2) what will happen if the developer disappears?

In fact, you have to become the new developer of this open-source project and look at the comment below:

SF-Lightning-Lookup:  //Using timeout and $A.getCallback() to avoid conflict between LookupChooseEvent and onblur​
 
//function to hide the list on onblur event.
    hideList :function (component,event,helper) {
        //Using timeout and $A.getCallback() to avoid conflict between LookupChooseEvent and onblur
        window.setTimeout(
            $A.getCallback(function() {
                if (component.isValid()) {
                    helper.toggleLookupList(component,
                        false,
                        'slds-combobox-lookup',
                        'slds-is-open'
                    );
                }
            }), 200
        );
    }

The first lookup component (2015) could be blocked now by the "Locker service" (always look at the comments at the botton of the page and the only thing you can do is cry if the developer has disappeared and you are unable to maintain the code by yourself).

That's why I am waitting for the Philipe Ozil's lookup component preferably because he is also the official Evangelist of Salesforce in France.
In the US,  there are also good developers for this kind of component probably.

And for Salesforce itself, there is no date (in the future, not before the end of the next year for <lightning:lookup>).
 
Alain CabonAlain Cabon
I have tested the "in progress" component of Philippe Ozil.

https://github.com/pozil/sfdc-ui-lookup


Multiselection with pills: works with Account and Opportunity (hard coded objects but the multiobject dropdown already works)

User-added image
User-added image
Responsive design (one column):
User-added image

The prepopulated value is like that (a pill):

User-added image
TestApp: it is an undocumented project (in progress) but the code is documented and I have just added 

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/> for testing the prepopulaled value.
 
<aura:application extends="force:slds" template="c:TestAppTemplate">
    
    <aura:attribute type="List[]" name="selection" default="[]"/>
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

    <div class="slds-form slds-form_stacked slds-m-around_xx-large">
        <c:lookup selection="{!v.selection}" label="Search" placeholder="Search Salesforce" isMultiEntry="true"/>
    </div>
</aura:application>

I have just modified the controller of the TestApp.
({
	doInit : function(component, event, helper) {
		   var prepopulatedvalue =  {'id':'0010Y00000WeuZn','title':'my company2','icon':'standard:account'};
           component.set('v.selection',prepopulatedvalue);
	}
})

His component will be really good soon I am sure.

Alain
Alain CabonAlain Cabon
Strike Lookup A form element for searching and selecting an existing record

http://www.lightningstrike.io/#!/strikeLookup

https://github.com/appiphony/Strike-Components/tree/master/aura/strike_lookup

Philippe Ozil also spoke about Strike.

That could be the "good" one.  I will test it.
Denise CrosbyDenise Crosby
Hi Alain,
Thanks so much for all your replies and research. I did try sfdcmonkey some yesterday, but haven't gotten it working yet. I probably don't need multi-select, just some basic component would be great. AllowNewRecords would be nice but probably not required. I looked at the link for Lightning Strike and I seem to remember hearing good things about this in the Lightning Development class I took recently. I am actually just trying to keep up with all the good ideas posted here.
Denise
Denise CrosbyDenise Crosby
I admit it's very disappointing that Salesforce does not have this component and there is no date yet provided for implementing it. Not good Salesforce... 
Alain CabonAlain Cabon
"I did try sfdcmonkey some yesterday, but haven't gotten it working yet" ... Don't be surprised, I have the same problems for almost all the open-source lookup components. 

In fact, all these open source project are  quite buggy (a new problem with the locker service, your data are different or much bigger, a column is missing and so on).  There is always a nice article on the blog page, a nice sample but when you try to use them, that often never works as expected (i know very well the problem and that's why I was expected the Philippe Ozil's final work (he could also write an article)(one month ago for his project) or Strike perhaps simply now (14 days ago) 

I also need this kind of lookup component for my future works. Helping you helps me too.

You are lucky because Strike seems on github since some days. It is a big project (not easy to install) but it should be maintain (... until a commercial version? that is the only risk).
Alain CabonAlain Cabon
Denise,  

You know what... Victory!  or Strike! like we say in bowling

You will adore this component.

User-added image
INSTALLATION & DEPENDENCIES: I installed the following files (just clicking on the links here (copy/paste): 
http://www.lightningstrike.io/#!/strikeLookup


a)  The following dependencies must also be saved to the org in order for the component to function:
  1. aura/defaultTokens      // it is a special kind of file in Lex (little used)
  2. aura/strike_evt
  3. aura/strike_tooltip
  4. aura/strike_svg
  5. classes/strike_lookupController.cls
  6. classes/strike_lookupController.cls-meta.xml
  7. classes/strike_responseData.cls
  8. classes/strike_responseData.cls-meta.xml
  9. classes/strike_tst_lookupController.cls
  10. classes/strike_tst_lookupController.cls-meta.xml
  11. classes/strike_utilities.cls
  12. classes/strike_utilities.cls-meta.xml

http://www.lightningstrike.io/#!/strikeLookup


b)  appiphony/Strike-Components​
  1. strike_lookup.cmp    
  2. strike_lookup.css    
  3. strike_lookupController.js
  4. strike_lookupHelper.js
  5. strike_lookupRenderer.js
https://github.com/appiphony/Strike-Components/tree/master/aura/strike_lookup

Create a simple lightning app at the end + Preview: 
<aura:application extends="force:slds" >
    
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <div class="slds-form slds-form_stacked slds-m-around_xx-large">
        <c:strike_lookup   aura:id="mylookupid"
                         label="Account"
                         object="Account"
                         searchField="Name"
                         placeholder="Select an option"
                         iconName="standard:account"
                         subtitleField="Industry"
                         order="Name"
                         limit="5"
                         loadingMessage="Loading..."
                         errorMessage="Invalid input"
                         allowNewRecords="false"
                         showRecentRecords="true"/>     

        <lightning:button variant="brand" label="Submit" onclick="{! c.handleClick }" />

    </div>
</aura:application>

doInit for testing the prepopulated field and handleclick for getting the selected value :
 
({
	doInit : function(component, event, helper) {
         var accountid = '0010Y00000WeuZrQAJ';       
         component.find("mylookupid").set("v.value",accountid);        
	},
    handleClick: function (component, event, helper) {
		var accountid = component.find("mylookupid").get("v.value");
        alert("value:" + accountid);
	},
})

That worked. Strike!

Alain
 
This was selected as the best answer
Alain CabonAlain Cabon
1) The best component if you need a prepopulated field is strkeLookup.
http://www.lightningstrike.io/#!/strikeLookup

2) If you don't need a prepopulated value, you can try the standard <force:inputfield> with the following workaround.

isalew'comment here: "I just finished a multi-month marathon with Salesforce R&D on the issue of <force:inputField>components not working. Here is the solution/workaround we achieved:"
https://developer.salesforce.com/forums/?id=906F0000000D6RwIAK

As usual, there are no other point of views from other developers here because very few people are using these Lex components in fact:
very difficult (multi-month marathon with Salesforce R&D) and not mature.

So when we found a lookup component which works like strkeLookup this is excellent news.
Denise CrosbyDenise Crosby
Thank you Alain,
I am trying to get the Strike_Lookup working in my Sandbox. I have run into a slight security hiccup which I am working through at the moment which should not be happening. Anyways, I will let you know how it goes. :) It is kind of exciting to be able to put this stuff in production.... when I can get it working. I already have one lightning component in production, which you collaborated with me on, thank you!!
Denise
Alain CabonAlain Cabon
Hello Denise,

Very interesting, so even Strike_Lookup is not working for your sandbox (very bad news).
We absolutely need this stuff in production. I am very disappointed.

"a slight security hiccup", that just doesn't smell good. 

What is the error message exactly?

The "locker service" is casting its threatening shadow on the Lex components, you know.
Denise CrosbyDenise Crosby
So, don't laugh but I can't get strike to install in my Sandbox. I am at this step here:

User-added image
And I get this:

User-added image

I am putting in my password with the security token right after it and I am a system administrator.

I was going to try in my personal developer org or create a new sandbox.

Maybe I'm doing something wrong. I don't know...
 
Alain CabonAlain Cabon
Ok, I didn't install the complete Strike-cli (the complete suite of tools?) which seems to have security issues.

I have installed just the components I need for the lookup (a little part, a surgical installation). 

This takes longer to do manually than your way probably (that I don't know) but it is sufficient.

Two steps installation:
1) The following dependencies must also be saved to the org in order for the component to function:
(click on every link and create each file, ok, it is laborious I know but the result will be great)
http://www.lightningstrike.io/#!/strikeLookup

2) The lookup component precisely (install each file again)
https://github.com/appiphony/Strike-Components/tree/master/aura/strike_lookup

You can try this way first and I will look at your way with the complete "Strike-cli".
Alain CabonAlain Cabon
For example, for the following files, I have just created a Lightning component named strike_lookup with the developer console and I copied/pasted all the "raw" source codes for each file. 

strike_lookup.cmp     // component
strike_lookup.cmp-meta.xml // useless
strike_lookup.css  // css
strike_lookupController.js  // controller

.. and so on. Manually.
Denise CrosbyDenise Crosby
OK, I will try that now.
Denise CrosbyDenise Crosby
Everything saved (as far as I know that is needed), so I will try it in my code next. :)
Alain CabonAlain Cabon
I hope good news from you soon. 

You can try a little lightning app like I have posted above + "Preview" directly in the developer console with a hard coded account id.
Denise CrosbyDenise Crosby
It works!!! :) Happy dance!!!
Alain CabonAlain Cabon
Did you use "record types" for your accounts?

The problem with these big open-source projects will be when someone will ask you: "I just want to find the accounts for this record type only" or "all the record types excepted this one" and with this complicated code, that could be quite difficult to meet the demands.
Denise CrosbyDenise Crosby
Hi Alain, I don't have any record types right now on accounts. I can probably make do with this Lightning Strike code until Salesforce comes out with their component. Thanks so much for your help. I could not have figured this out without your help! Denise
Alain CabonAlain Cabon
Let me know if you find a problem during your acceptance tests. I will use this great component for my own company probably and you could have some first good indications during the coming days (stablility and speed of the responses for example)
Denise CrosbyDenise Crosby
I sure will!
Alain CabonAlain Cabon
By the way, I looked at the known issues and there was only one before the latest release (not sure now for this issue and there is a workaround for the Utility Bar).

waltonzt : We upgraded their package to a latest version since I have not seen it happen in the latest version.
We did have to modify the strike_lookup js Controller with the line if(!lookupMenu){ return; } In the handleFocusIndexChange function because we were getting another error when using a strike lookup on a page which is accessed from the Utility Bar. Im thinking maybe this fixed the issue as well but do not know.

https://github.com/appiphony/Strike-Components/issues/117

The stability seems good.
Denise CrosbyDenise Crosby
Hi Alain,
I ended up using 3 of these Strike Lookup components in my Lightning Component. After making a selection in the first one, I was hoping to fire an event to restrict or make an automatic selection in the second one. I haven't been able to get that to work though. Seems like there would be an event like onselect or something, but couldn't find anything. Am I missing something?
Thanks again for all your wonderful help.
Denise
Alain CabonAlain Cabon
Hi Denise,

Interesting case indeed as always with your questions.

Did you try to Detect Data Changes with Change Handlers (that is the solution for your problem for sure).
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_cb_data_change.htm

It is an easy technique when you want to update a value in a field when another value has changed elsewhere.

This technique used below that you can adapt easily updating the method itemsChange for your need.

<aura:handler name="change" value="{!v.myaccountid}" action="{!c.itemsChange}"/>
<c:strike_lookup aura:id="mylookupid" value="{!v.myaccountid}"

If I change the first account (v.myaccountid) , the second field (v.myaccountid2) is updated with the same value.
User-added image
({
	doInit : function(component, event, helper) {
         var accountid = '0010Y00000WeuZrQAJ';       
      // component.find("mylookupid").set("v.value",accountid);  
         component.set('v.myaccountid',accountid);      
	},
    handleClick: function (component, event, helper) {
	//	var accountid = component.find("mylookupid").get("v.value");
	    var accountid = component.get("v.myaccountid");
        alert("value:" + accountid);
	},
    itemsChange: function (component, event, helper) {
	    var accountid = component.get("v.myaccountid");
        component.set('v.myaccountid2',accountid);
	},
})
 
<aura:handler name="change" value="{!v.myaccountid}" action="{!c.itemsChange}"/>
    
    <aura:attribute name="myaccountid" type="String"  />
    <aura:attribute name="myaccountid2" type="String"  />
     
    <div class="slds-form slds-form_stacked slds-m-around_xx-large">
        <c:strike_lookup aura:id="mylookupid"
                         value="{!v.myaccountid}"
                         label="Account"
                         object="Account"
                         searchField="Name"
                         placeholder="Select an option"
                         iconName="standard:account"
                         subtitleField="Industry"
                         order="Name"
                         limit="5"
                         loadingMessage="Loading..."
                         errorMessage="Invalid input"
                         allowNewRecords="false"
                         showRecentRecords="true"/>  
         <c:strike_lookup aura:id="mylookupid2"
                         value="{!v.myaccountid2}"
                         label="Account"
                         object="Account"
                         searchField="Name"
                         placeholder="Select an option"
                         iconName="standard:account"
                         subtitleField="Industry"
                         order="Name"
                         limit="5"
                         loadingMessage="Loading..."
                         errorMessage="Invalid input"
                         allowNewRecords="false"
                         showRecentRecords="true"/>     
        <lightning:button variant="brand" label="Submit" onclick="{! c.handleClick }" />
    </div>
</aura:application>

 I always find you very good to work with.

By the way: updates for strike version 0.10.1 => just an hour ago
https://github.com/appiphony/Strike-Components/tree/master/aura/strike_lookup

Alain
Denise CrosbyDenise Crosby
I will try this today and get it working. Thank you so much!!
Denise CrosbyDenise Crosby
Detect Data Changes with Change Handlers works. I was looking for an event on the strike component which was wrong. The aura handler sees the data change in the value provider. Thank you again. Excellent explanation!
Alain CabonAlain Cabon
Good news. The sample of strikeLookup doesn't use the attribue "value" explicitly (that doesn't help) so I got it indrectly by finding it with the aura:id at first as it is explained in the documentation.

Working with Attribute Values in JavaScript: To retrieve an attribute value of a component reference, use component.find("cmpId").get("v.value"). Similarly, use component.find("cmpId").set("v.value", myValue) to set the attribute value of a component reference.

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/js_attr_values.htm

I just tried to set the attribute value indirectly with another attribute for your question and that also works but you will not find this trick easily for the component strikeLookup writen like that. There is perhaps another technique to use the attribute v.value of the component strikeLookup directly without the need of a new attribute as you tried to find at the beginning but that doesn't seem possible (your first statement).

http://www.lightningstrike.io/#!/strikeLookup
Denise CrosbyDenise Crosby
Hi Alain,
Happy Friday! I got the new version of strike_lookup. Thank you!!
I am stuck on one last thing before I can move this to production, and was hoping I haven't overused your help. :)

When a user makes a selection in the first strike_lookup component, I'm trying to change the filter on the second strike_lookup component. I can't figure out how to do this. I'm trying to do something like this in my Helper Javascript but it doesn't work. Hopefully this is something really simple that I'm missing.

component.set("c.sitelookup.filter", "id = '0010x000002IkucAAC'")

NewOppLEX.cmp:
<aura:handler name="change" value="{!v.siteID}" action="{!c.siteChange}"/> 
<aura:handler name="change" value="{!v.newOpp.AccountId}" action="{!c.ownerChange}"/> 

<c:strike_lookup aura:id="ownerlookup" 
                                     value="{!v.newOpp.AccountId}"
                                     label="Owner" 
                                     object="Account"
                                     searchField="Name"
                                     placeholder="Select an owner"
                                     iconName="standard:account"
                                     filter="type = 'owner'"
                                     order="Name"
                                     limit="5"
                                     loadingMessage="Loading..."
                                     errorMessage="Invalid input"
                                     class="slds-p-horizontal_x-small"
                                     required="true"/>
<c:strike_lookup aura:id="sitelookup"                                     
                                     value="{!v.siteID}"
                                     label="Site"
                                     object="Account"
                                     searchField="Name"
                                     placeholder="Select a site"
                                     iconName="standard:account"
                                     filter="type = 'site'"
                                     order="Name"
                                     limit="5"
                                     loadingMessage="Loading..."
                                     errorMessage="Invalid input"
                                     class="slds-p-horizontal_x-small"
                                     required="true"/>

NewOppLEXController.js:
siteChange: function (component, event, helper) {
        var SiteID = component.get("v.siteID");
    	helper.setOwner(component, SiteID);    
    },
    
ownerChange: function (component, event, helper) {
        var OwnerID = component.get("v.newOpp.AccountId");
    	helper.getSites(component, OwnerID);    
    }

NewOppLEXHelper.js:
setOwner: function(component, siteID){
        var action = component.get("c.getOwner");
        action.setParams({
            "siteID": siteID,
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.newOpp.AccountId", response.getReturnValue());
                //component.set("v.newOpp.AccountId", '0010x000002IkucAAC');         
            }
        });
        $A.enqueueAction(action);
    },
    
getSites: function(component, ownerID){
        var action = component.get("c.getSites");
        action.setParams({
            "ownerID": ownerID,
        });
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                //component.set("c.sitelookup.filter", "id = '0010x000002IkucAAC'")
            }
        });
        $A.enqueueAction(action);
    },
NewOppLEX.apxc:
@AuraEnabled
    public static string getOwner (string siteID) {
        
        Account A = [select id,ParentId from Account where id = :siteId];
        return A.ParentId;
    }
    
    @AuraEnabled
    public static Account[] getSites (string ownerID) {
        
        Account[] sites = [select id from Account where parentid = :ownerID];
        return sites;
    }

Thank you for taking your valuable time to look at this.
Denise
Denise CrosbyDenise Crosby
Hey, I think I got this whole thing figured out, finally. I set the filter="{!v.filter}"in the markup. I think I'm ready for production :)
Alain CabonAlain Cabon
Excellent Denise. You were very smart to solve this new problem. You proceed too rapidly for me. I didn't have enough time to answer "something".

Have a great weekend! 

Alain
Denise CrosbyDenise Crosby
Hi Alain,
I hope you are doing great. Wanted to let you know I finally deployed this to production with strike_lookup! Everything seems to be working fine. The only minor glitch we found was on iPhone 6s. You can't see what you're typing into the 3rd strike_lookup component when you're typing into it, like in the below image. Very strange, but we can probably live with it for now. It works fine on Android. :) Anyway, thanks again for all your great help.

User-added image


Component Markup:
<aura:component controller="NewOppLEX" implements="flexipage:availableForAllPageTypes,lightning:actionOverride" access="global" >
  
    <aura:attribute name="opps" type="Opportunity[]"/>
    <aura:attribute name="newOpp" type="Opportunity"
                    default="{'sobjectType': 'Opportunity', 'Name': '', 'AccountId': '', 'Amount': 0 }"/>
    <aura:attribute name="siteID" type="string"/>
    <aura:attribute name="contractorID" type="string"/>
    <aura:attribute name="screenSize" type="string"/>
    <aura:attribute name="filter" type="string"/>   
    <aura:attribute name="Err" type="string"/>  

    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:handler name="change" value="{!v.siteID}" action="{!c.siteChange}"/> 
    <aura:handler name="change" value="{!v.newOpp.AccountId}" action="{!c.ownerChange}"/> 
  
  <!--Removing lightning:layout and lightning:layoutItem as it caused problem with strike_lookup field expanding after selecting a long site name, making the screen unusable on mobile -->
  <!--  <lightning:layout > 
        <lightning:layoutItem padding="around-small" size="{!v.screenSize}" class="slds-align_absolute-center"> -->
            <lightning:card iconName="standard:opportunity" title="New Opportunity">
                <form class="slds-form--stacked">         
                     
                    <c:strike_lookup aura:id="sitelookup"                                     
                                     value="{!v.siteID}"
                                     label="Site"
                                     object="Account"
                                     searchField="Name"
                                     placeholder="Select a site"
                                     iconName="standard:account"
                                     filter="{!v.filter}"
                                     order="Name"
                                     limit="5"
                                     loadingMessage="Loading..."
                                     errorMessage="Invalid input"
                                     class="slds-p-horizontal_x-small"
                                     required="true"/>
                    
                    <c:strike_lookup aura:id="ownerlookup" 
                                     value="{!v.newOpp.AccountId}"
                                     label="Owner" 
                                     object="Account"
                                     searchField="Name"
                                     placeholder="Select an owner"
                                     iconName="standard:account"
                                     filter="type = 'owner'"
                                     order="Name"
                                     limit="5"
                                     loadingMessage="Loading..."
                                     errorMessage="Invalid input"
                                     class="slds-p-horizontal_x-small"
                                     required="true"/>
                   
                    <c:strike_lookup aura:id="contractorlookup"                                     
                                     value="{!v.contractorID}"
                                     label="Contractor" 
                                     object="Account"
                                     searchField="Name"
                                     placeholder="Select a contractor"
                                     iconName="standard:account"
                                     filter="type = 'contractor'"                                     
                                     order="Name"
                                     limit="5"
                                     loadingMessage="Loading..."
                                     errorMessage="Invalid input"
                                     class="slds-p-horizontal_x-small"/>                      
                    
                    <lightning:input aura:id="oppform" label="Opportunity Name"
                                     name="oppname"
                                     value="{!v.newOpp.Name}"
                                     required="true"
                                     class="slds-p-horizontal_x-small"/>
                    
                    <lightning:input type="number" aura:id="oppform" label="Revenue"
                                     name="revenue"
                                     value="{!v.newOpp.Amount}"
                                     required="true"
                                     class="slds-p-horizontal_x-small"/>
                    
                    <lightning:input type="date" aura:id="oppform" label="Estimated Close Date"
                                     name="closedate"
                                     value="{!v.newOpp.CloseDate}"
                                     required="true"
                                     class="slds-p-horizontal_x-small"/>
                    
                    <p>     <div class="slds-text-color_error" >     <ui:outputText value="{!v.Err}" /></div></p>
                   
                    <lightning:button label="Save"
                                      class="slds-m-around_small"
                                      variant="brand"
                                      onclick="{!c.clickCreate}"/>
                </form>
            </lightning:card>
    <!--    </lightning:layoutItem>
    </lightning:layout> -->
    
</aura:component>

 
Alain CabonAlain Cabon
Hi Denise,

Very interesting feedback. It is related to this question but I am not using this component for the mobile right now.

I am not a specialist of the mobile applications. You can emulate nearly all the devices on Chrome but that is very specific (not sure an emulator would have the same result).

You "could" try to add the interface: implements="force:appHostable" by the way (not tested and your problem is just for iPhone 6s and perhaps redundant with flexipage:availableForAllPageTypes).

The most interesting ressource is ... the known issues:

Salesforce1 iOS scrolled up just after filling in a lookup field
Mobile
Last updated 2017-07-28 ·Reference W-2870430 ·Reported By 6 users
IN REVIEW
Summary
Using Salesforce1 app for iOS, when opening a new page, scrolling down and filling in a lookup field, then immediately being scrolled up to the top.
https://success.salesforce.com/issues_view?id=a1p30000000jd42AAA&title=salesforce1-ios-scrolled-up-just-after-filling-in-a-lookup-field

I am not fluent in English so that could be a totally different problem (otherwise, there is ... no real solution excepted waiting for the fix).

Alain
Denise CrosbyDenise Crosby
Hi Alain,
I hope you are well. I checked the roadmap again and the lookup is missing. Did they rename it something else?

https://help.salesforce.com/articleView?id=lightning_components_roadmap.htm&type=0

I am working with a developer now and he is having problems creating a lookup to account from the opportunity object within Visual Workflow. It shouldn't be this difficult!!

Thanks
Denise
Alain CabonAlain Cabon
Hello Denise,

There are constrainsts indeed (look at the idea below for the first feedbacks) and you could still prefer Strike Lookup.
It is not  <lightning:Lookup> anymore but <lightning:inputField> (like <apex:inputField> for the VFP.

Marcus Torres and Greg Rewis (Salesforce) communicated on this new component (idea).

Lightning:inputField (Beta)
https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/aura_compref_lightning_inputField.htm

Add Lookup Field Lightning Component : the idea is interesting for the comments.
You can use <lightning:inputField> with a lookup field in Spring '18 ( Markus Torres )
https://success.salesforce.com/ideaView?id=08730000000Dom1AAC

Alain
Alain CabonAlain Cabon
Hi Denise,

When you talk about Lex components in flows, it is very new (Spring '18).

Spring ’18 for Developers: Go with the Flow Like Never Before
Spring ’18 holds a ton of exciting features for developers. We’ll be covering a number of these in a series of posts like this one. In this post, we’re going to focus on a few (completely awesome) changes to flow: launching a flow from an object-specific action, and adding custom Lightning Components to flow.
https://developer.salesforce.com/blogs/2018/01/spring-18-for-developers-flow.html

The exciting dream comes true excepted for ... the inputField that doesn't implement <lightning:availableForFlowScreens>?

Markus Torres will very likely give you a clear explanation.
 
Alain CabonAlain Cabon
A good start! 
<aura:component implements="lightning:availableForFlowScreens"> 
  <div class="slds-p-bottom_large slds-p-left_large" style="width:500px">
        <lightning:recordEditForm aura:id="recordViewForm" 
                                  recordId="0035800000HsFyd"
                                  objectApiName="Contact">
            <lightning:messages />
            <lightning:inputField fieldName="FirstName" />
            <lightning:inputField fieldName="LastName" />
            <lightning:inputField fieldName="Birthdate" />
            <lightning:inputField fieldName="Phone" />
            <lightning:inputField fieldName="AccountId" />
        </lightning:recordEditForm>
    </div>  
</aura:component>
Still good ...

User-added image
But the change of the value for Account ID (lookup) fails ( wait indefinitely.)

User-added image


User-added image

User-added image

The inevitable conclusion is: UNUSABLE.
Denise CrosbyDenise Crosby
Thanks Alain. I was wondering how you respond to Marcus Torres about the lookup field not having the same functionality as a lookup? I don't have a lot of time to test it out because I'm behind on several aspects of my project, but I can tell from reading all the comments that they have overpromised and underdelivered.
Alain CabonAlain Cabon
Denise, your question about the flow and  <lightning:inputField> is easy to understand and test.

More generally, you always need this part of code:
<lightning:recordEditForm aura:id="recordViewForm" 
                                  recordId="0035800000HsFyd"
                                  objectApiName="Contact">

Question: Jaap Branderhorst - 1 month ago
<lightning:inputField> only works in the context of <lightning:recordEditForm>. Please give us a 'standalone' lookup field.

Answer: Marcus Torres - 1 month ago
...
We are looking into release a separate lookup component but it will have also require a way to pass context of which record the lookup field is related to. 

There will be a new lookup component hence.

Wait and see for the next Markus Torres's answers.

Alain
Muddassar JawedMuddassar Jawed
Hi Denise,

My problem with using filter is like when i use the Strike Component object as opportunity and use the lookup. It searches for all the opportunity. My requirement is, it should only search for the account with which the opportunity is associated with.

<c:strike_lookup aura:Id="OPP" label="Opportunity"
                                        object="Opportunity"
                                        searchField="Name"
                                        placeholder="Select an Existing Opportunity for above"
                                        iconName="standard:account"
                                        filter="AccountId=:'!v.accountIDforurl'"            
                                        value="{!v.opportunity}"                
                                        order="Name"
                                        limit="5"
                                        loadingMessage="Loading..."
                                        errorMessage="Invalid input"/> 

As you can see in my Strike lookup. I am using the filter "filter="AccountId=:!v.accountIDforurl" . Where "v.accountIDforurl" is the id of the Account which will limit my query to minimum no. of record.

My debug is coming this way. Its not populating the value of account and the query fails.

SELECT Id, Name FROM Opportunity WHERE Name LIKE '%Gre%' AND (AccountId=:'!v.accountIDforurl')

Thanks in Advance
{tushar-sharma}{tushar-sharma}
You can try this one, the code is cleand it supports prepopulate values also.
https://newstechnologystuff.com/2018/07/07/custom-lookup-lightning-component/

If you are looking similar in Lightning web components, you can try this one
https://newstechnologystuff.com/2019/05/01/custom-lookup-in-lightning-web-components/