custom-lookup-multiselect-lightning

Reusable Multi Select Custom Lookup In Salesforce Lightning Component

Lightning Component

Welcome back guys, today in this post we are going to learn, how we can create custom multi select lookup with salesforce lightning components.

Multi-Select Lookup Component Functionality :

  • Multi Record Section (multi select lookup).
  • Re-usable.
  • Prevent duplicate record selection and more…
Output :

multiselect-lookup-lightning

Component Blue Print :

multiselect lookup blueprint

Step 1 : Create Apex Class Controller.
Apex class [reUsableMultiSelectLookupCtrl.apxc]

Step 2 : Create Lightning Event
  • Next we create a Lightning Event bundle for communicate data(attribute values) between different components. (Child To Parent Component )
  • Events are contain attributes that can be set before the event is fired and read when the event is handled by component.

from developer console >> file >> new >> Lightning Event >> enter name >> selectedsObjectRecordEvent >> save

lightning Event [selectedsObjectRecordsEvent.evt]

Step 3 : Create Child Component For Display the Search Result List
Lightning Component [reUsableMultiSelectLookupResult.cmp] 

client side JavaScript Controller :[reUsableMultiSelectLookupResultController.js]

Step 4 : Create Parent Component
Lightning Component [reUsableMultiSelectLookup.cmp]

client side JavaScript Controller :[reUsableMultiSelectLookupController.js]

client side JavaScript Helper :[reUsableMultiSelectLookupHelper.js]

Component CSS :[reUsableMultiSelectLookup.CSS]

TestApp.app

This is a dynamic Re-Usable Lightning Component you have need to pass the objectAPIName , IconName, selected Records List and Field Label  Attributes when use this Custom Multi-select Lookup component.

Check Also : Single Selection Custom Lookup Component in Lightning Component 
Custom Salesforce Lightning Multi select lookup Output : 

multiselect-lookup-lightning

 

Related Resources :

Custom Single Lookup Lightning Component

https://www.lightningdesignsystem.com/icons/#standard

Salesforce Lightning Design System Lookup

Lightning Component Events

Like our facebook page for new post updates. & Don’t forget to bookmark this site for your future reference.

if you have any suggestions or issue with it, you can post in comment box  🙂

(Visited 6,226 times, 27 visits today)

26 comments

  • Hi

    Can this component be used in lightning for outlook?. i have tried using other lightning components in lightning for outlook to be able to customize the email pane, but not this.

  • HI ,

    I am getting bellow error when i use the above code how can solve that. Please help me.

    This page has an error. You might just need to refresh it. Unable to find ‘fetchLookUpValues’ on ‘compound://veeru.reUsableMultiSelectLookup’. Failing descriptor: {markup://veeru:reUsableMultiSelectLookup}

  • I am getting this error. Could you please provide me with this event.

    Failed to save reUsableMultiSelectLookup.cmp: No EVENT named markup://c:post_selectedsObjectRecordsEvent found

  • On clicking the drop down value,

    This page has an error. You might just need to refresh it. Action failed: c:reUsableMultiSelectLookup$controller$handleComponentEvent [Cannot read property ‘Push’ of undefined] Failing descriptor: {c:reUsableMultiSelectLookup$controller$handleComponentEvent}

    Any help?

     

    Thanks

    Heamnth

  • How to re-use the same component multiple times in the app?

    For Example: I want to display 2 multi select lookups in the same app. How can I extend this ? and also I want to extend it with dependency in below example base on country selection I want to filter states.

    Thanks for your help!!! You post is really great!!

     

    like:
    <aura:application extends=“force:slds”>
      <!– Create attribute to store lookup value as a sObject–>
      <aura:attribute name=“selectedLookUpRecords” type=“sObject[]” default=“[]”/>

      <c:reUsableMultiSelectLookup objectAPIName=Country
                                   IconName=“standard:account”
                                   lstSelectedRecords=“{!v.selectedLookUpRecords}”
                                   label=“Account Name”/>

      <c:reUsableMultiSelectLookup objectAPIName=State
                                   IconName=“standard:account”
                                   lstSelectedRecords=“{!v.selectedLookUpRecords}”
                                   label=“Account Name”/>

       <!– here c: is org. namespace prefix–>
    </aura:application>

  • Hi! Once you’ve entered the code, how do you find the component that was created in Salesforce?
    -> I would like to add this element in my account page to lookup and add several products that are linked to this account.

    How do I do this now that the code is entered?

    Thanks,

  • HI I jus need to find Email of contact object

     <c:reUsableMultiSelectLookup objectAPIName=“Contact“
                                   IconName=“standard:account”
                                   lstSelectedRecords=“{!v.selectedLookUpRecords}”
                                   label=“Account Name”/>

       <!– here c: is org. namespace prefix–>

    What need to change here please help me

  • Hi, how do you launch/implement this after the code is done? I’m not a developer by any stretch and could use help launching

  • Hi This is great. How do I go about saving the value of the pick list into an object – Say if I wanted to place it within a tab

  • Hi,

    quick question about this topic. once we choose specific contact under the account, can we save it some how? and it’ll be attached to the account and updated in the DB?

    for example i need to attach several contacts to the opportunity, and i cant use contact role and i prefer not to create new related list. is that solution can be useful? i need to set several “internal” contacts to one opportunity.

    thanks

  • Sorry, maybe my issue is stupid, but I’m new in lightning, was using mostly Classic UI.
    Straight to point:
    I was able to follow all your steps, reproduce them. After pushed TestApp preview button, App works perfectly!

    Now question, how can I add this into page layout? I would like it to be visible on the Account.
    Inside app builder i’m not able to see custom component.

    Thank you!

    It’s not that simple, like putting inside page layout visual component.
    Can you please share this with me? Thank you in Advance!

  • how to set default values for <aura:attribute name=“lstSelectedRecords” type=“sObject[]” default=“[]” description=“Use,for store SELECTED sObject Records”/>

    can i  know the sysntax?

     

  • Attempting to use this in a flow and save the multi-pick lookup IDs in a collection variable. However, the IDs are not being saved properly – any thoughts?

Leave a Reply