You need to sign in to do that
Don't have an account?
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
NewOpp.cmp
NewOppController.js
NewOppHelper.js
Thanks so much for your help!
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!
You know what... Victory! or Strike! like we say in bowling
You will adore this component.
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:
http://www.lightningstrike.io/#!/strikeLookup
b) appiphony/Strike-Components
- strike_lookup.cmp
- strike_lookup.css
- strike_lookupController.js
- strike_lookupHelper.js
- strike_lookupRenderer.js
https://github.com/appiphony/Strike-Components/tree/master/aura/strike_lookupCreate a simple lightning app at the end + Preview:
doInit for testing the prepopulated field and handleclick for getting the selected value :
That worked. Strike!
Alain
All Answers
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
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
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
Please check below link for your solution, it will may help you :
http://www.sfdcmonkey.com/2017/07/17/re-usable-custom-lookup/
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
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.
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
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>).
https://github.com/pozil/sfdc-ui-lookup
Multiselection with pills: works with Account and Opportunity (hard coded objects but the multiobject dropdown already works)
Responsive design (one column):
The prepopulated value is like that (a pill):
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.
I have just modified the controller of the TestApp.
His component will be really good soon I am sure.
Alain
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.
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
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).
You know what... Victory! or Strike! like we say in bowling
You will adore this component.
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:
http://www.lightningstrike.io/#!/strikeLookup
b) appiphony/Strike-Components
- strike_lookup.cmp
- strike_lookup.css
- strike_lookupController.js
- strike_lookupHelper.js
- strike_lookupRenderer.js
https://github.com/appiphony/Strike-Components/tree/master/aura/strike_lookupCreate a simple lightning app at the end + Preview:
doInit for testing the prepopulated field and handleclick for getting the selected value :
That worked. Strike!
Alain
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.
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
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.
And I get this:
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...
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".
strike_lookup.cmp // component
strike_lookup.cmp-meta.xml// uselessstrike_lookup.css // css
strike_lookupController.js // controller
.. and so on. Manually.
You can try a little lightning app like I have posted above + "Preview" directly in the developer console with a hard coded account id.
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.
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.
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
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.
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
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
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:
NewOppLEXController.js:
NewOppLEXHelper.js: NewOppLEX.apxc:
Thank you for taking your valuable time to look at this.
Denise
Have a great weekend!
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.
Component Markup:
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
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
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
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.
But the change of the value for Account ID (lookup) fails ( wait indefinitely.)
The inevitable conclusion is: UNUSABLE.
More generally, you always need this part of code:
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
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
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/