• This repository has been archived on 05/Oct/2022
  • Stars
    star
    102
  • Rank 335,584 (Top 7 %)
  • Language
    JavaScript
  • License
    Apache License 2.0
  • Created almost 7 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Salesforce Lookup Component (Aura version, maintenance only, see LWC version for updates)

Salesforce Lookup Component (Aura version, maintenance only)

⚠️This Aura version is no longer maintained.
New features are only added to the Lightning Web Component version.

Lookup animation

Lookup with dropdown open

About

This is a generic & customizable lookup component built using Salesforce Lightning (Aura) and SLDS style.
It does not rely on third party libraries and you have full control over its datasource.

Features

The lookup component provides the following features:

  • customizable data source that can return mixed sObject types
  • single or multiple selection mode
  • client-side caching & request throttling
  • built-in server request rate limit mechanism

Multiple or single entry lookup

Documentation

The lookup component is documented using Aura documentation.
You can access it from this URL (replace the domain):
https://<YOUR_DOMAIN>.lightning.force.com/docs/component-library/bundle/c:Lookup/documentation

Follow these steps in order to use the lookup component:

Basic use

1) Write the search endpoint

Implement an Apex @AuraEnabled method (SampleLookupController.search in our samples) that returns the search results as a List<LookupSearchResult>. The method name can be different but it needs to match this signature:

@AuraEnabled
public static List<LookupSearchResult> search(String searchTerm, List<String> selectedIds) {}

2) Handle the search event and pass the results to the lookup

The lookup component exposes an onSearch component event that is fired when a search needs to be performed on the server-side. The parent component that contains the lookup must handle the onSearch event:

<c:Lookup selection="{!v.selection}" onSearch="{!c.lookupSearch}" label="Search"/>

The event handler should do the following:

lookupSearch : function(component, event, helper) {
    // Get the lookup component that fired the search event
    const lookupComponent = event.getSource();
    // Get the Apex server-side action associated with this search (`search` in our samples)
    const serverSearchAction = component.get('c.search');
    // Passes the action to the lookup component by calling the `search` aura method
    lookupComponent.search(serverSearchAction);
}

Advanced use case: custom search parameters

If you need to pass custom parameters like a record id to the Apex search method, you can write the following search event handler:

lookupSearch : function(component, event, helper) {
    // Get the lookup component that fired the search event
    const lookupComponent = event.getSource();
    // Get the SampleLookupController.search server side action
    const serverSearchAction = component.get('c.search');
    // You can pass optional parameters to the search action
    // but you can only use setParam and not setParams to do so
    serverSearchAction.setParam('recordId', component.get('v.recordId'));
    // Passes the action to the Lookup component by calling the search method
    lookupComponent.search(serverSearchAction);
},

And use a custom Apex search method with your extra parameters:

@AuraEnabled(cacheable=true)
public static List<LookupSearchResult> search(String searchTerm, List<String> selectedIds, String recordId) {

}

Advanced use case: lookups in an iteration

If you use lookups in an iteration and need to adjust the search logic based on some iteration parameter, follow these steps.

Wrap the Lookup in a div with a dynamic dataset attribute like so:

<aura:iteration items="{!v.rows}" var="row" indexVar="index">
  <div data-row-index="{!index}">
    <c:Lookup .../>
  </div>
<aura:iteration>

Then, in your search function, do that:

lookupSearch : function(component, event, helper) {
  // Get the lookup component that fired the search event
  const lookupComponent = event.getSource();
  // Get the row index from the parent div
  const rowIndex = lookupComponent.getElement().parentNode.dataset.rowIndex;

  // Handle the rest of the search logic
  // You can use different search endpoints depending on the row index for example
}

Salesforce DX setup instructions

Deploy the sample application with the Salesforce CLI.

Sample application

The default installation installs the lookup component and a sample application available under this URL (replace the domain):
https://<YOUR_DOMAIN>.lightning.force.com/c/SampleLookupApp.app

If you wish to install the project without the sample application, edit sfdx-project.json and remove the src-sample path.

More Repositories

1

sfdc-ui-lookup-lwc

Salesforce Lookup Component built with Lightning Web Components.
JavaScript
582
star
2

streaming-monitor

A Lightning app for monitoring streaming events: PushTopic, generic, platform events, CDC events and monitoring events.
JavaScript
121
star
3

pub-sub-api-node-client

A node client for the Salesforce Pub/Sub API
JavaScript
70
star
4

salesforce-react-integration

Sample integration project between Salesforce and a React.js application
JavaScript
68
star
5

ui-api-playground

A sample Lightning Web Component (LWC) app that lets you explore the UI APIs and execute them.
JavaScript
64
star
6

auto-assign-issue

GitHub Action that auto-assigns issues or PRs to one or more users
JavaScript
55
star
7

apex-dependency-injection

Apex Dependency Injection Sample
Apex
38
star
8

sfdc-error-playground

Lightning & Apex Error Playground
JavaScript
31
star
9

sfdc-lightning-component-event-playground

Lightning Component Event Playground
JavaScript
30
star
10

sfdc-ui-modal

Salesforce Lightning Modal Component (Deprecated)
JavaScript
26
star
11

sf-docs-to-s3

Export Salesforce Documents to Amazon S3
Apex
23
star
12

spm-plugin

A Salesforce CLI plugin for interacting with the unofficial Salesforce Package Manager (SPM) registry.
TypeScript
22
star
13

picklist-utils

Apex utility class for working with Picklists with built-in cache
Apex
21
star
14

server-action-service

Generic and reusable Lightning service component that calls server-side actions
JavaScript
20
star
15

sfdc-ui-tree

Salesforce Lightning Tree Component (Deprecated)
JavaScript
20
star
16

csv-visualizer

A visualizer that parses CSV data and renders it in a table in Postman or in a browser.
JavaScript
19
star
17

bonita-angular-dashboard

Bonita Dashboard built on AngularJS integrated as a custom page (Deprecated)
JavaScript
18
star
18

legacy-api-scanner

Scan for Salesforce Legacy API calls
17
star
19

salesforce-unity-sdk

Salesforce SDK for Unity
C#
16
star
20

async-lwc-demo

Asynchronous Lightning Web Component Demo
JavaScript
16
star
21

dynamic-interactions-demo

Sample Lightning Web Component (LWC) app that lets you explore Dynamic Interactions.
JavaScript
15
star
22

codetour-watch

GitHub Action that flags file changes that may affect CodeTour content
JavaScript
15
star
23

sf-docs-from-s3

Middleware app that allows to download Amazon S3 documents from Salesforce
JavaScript
15
star
24

sandbox-user-init

Sandbox initialization class that creates admin users based on custom metadata from production
Apex
13
star
25

apex-sorting

Sample Code for Sorting in Apex
Apex
13
star
26

pub-sub-api-java-client

A sample Java gRPC client for the Salesforce Pub/Sub API
Java
12
star
27

picklist-service

Generic and reusable Lightning service component that retrieves picklist entries (Archived)
Apex
12
star
28

picklist-buttons

LWC, picklist, buttons
JavaScript
10
star
29

sfdc-ui-popover

Salesforce Lightning Popover Component (Deprecated)
CSS
10
star
30

sfdc-ui-modal-sample

Sample application for Lightning Modal component
JavaScript
8
star
31

lightning-singleton

Lightning component that acts a singleton
JavaScript
8
star
32

apex-security-update-summer21

Helper script for Salesforce Summer '21 Apex security update
Java
7
star
33

platform-event-service

Generic and reusable Lightning service component that publishes and subscribes to platform events (Partially Deprecated)
JavaScript
7
star
34

mongodb-jndi-datasource

A JNDI pooled datasource for MongoDB
Java
6
star
35

lws-fullcalendar-test

Testing FullCalendar lib with LWS
JavaScript
6
star
36

image-labeller

Image labeller for Salesforce Einstein Object Detection
JavaScript
5
star
37

bonita-angular-portal

A custom portal for Bonita BPM built with AngularJS and Bootstrap (Deprecated)
HTML
5
star
38

whac-a-console-app

A fun game of speed and skills that demonstrates how to navigate Console apps with LWC.
JavaScript
5
star
39

pardot-embedded-feedback

Gather instant feedback from prospects within Pardot Emails with Lightning Web Components.
JavaScript
4
star
40

pwm-controller

Node.js React app that controls servos via a PWM Hat mounted on a Raspberry Pi
JavaScript
4
star
41

devops-workshop

DevOps workshop with Lightning Web Runtime and GitHub Actions
JavaScript
3
star
42

spm-registry

This repository contains the SPM registry
JavaScript
3
star
43

postman-extractor

Postman Extractor (pmx) is a utility that extracts/compacts resources from Postman export files for easier versioning.
JavaScript
3
star
44

d3-word-cloud-lwc

A D3 Word Cloud Lightning Web Component
JavaScript
3
star
45

emp-api-test

JavaScript
2
star
46

gcal-cleaner

Google Calendar cleaner app
JavaScript
2
star
47

styling-lwc-oss

A sample LWC OSS application using a third party CSS Framework (Bulma)
HTML
2
star
48

lwc-svg-sample

Shell
1
star
49

salesforce-wef-vr

Salesforce Shelter VR Workshop
1
star
50

search-replace

JavaScript
1
star
51

bonita-doc-manager

Bonita Document Manager Custom Page implemented with AngularJS (Deprecated)
JavaScript
1
star
52

lwc-style-challenge

Base project for the LWC Style Challenge
HTML
1
star
53

lwc-picklist-path

A LWC path component that works with any picklist field
JavaScript
1
star
54

cometd-node-client

CometD client for Node.js that adds support for promises
JavaScript
1
star
55

event-lab-demo

TDX/DF LAB demo
Shell
1
star