Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.
/ picklist-service Public archive

Generic and reusable Lightning service component that retrieves picklist entries (Archived)

License

Notifications You must be signed in to change notification settings

pozil/picklist-service

Repository files navigation

Salesforce Lightning Picklist Service Component

⚠️ This project is archived ⚠️

Consider moving to Lightning Web Components. See the Retrieving Picklist Values Without Using Apex blog post and the sample LWC repository.

About

This is a generic and reusable Lightning component that retrieves any picklist entries.
This is a service component so it has no user interface of it's own: it is meant to be called by other components.

Features

The component provides the following features:

  • fetches picklists for any dynamic object (standard or custom) and field names
  • integrated error notifications (developer console + toast notifications in Lightning Experience)
  • storable actions for client-side cache
Sample app screenshot

Documentation

The component is documented using Aura documentation.
You can access it from this URL (replace the domain):
https://<YOUR_DOMAIN>.lightning.force.com/auradocs/reference.app#reference?descriptor=c:PicklistService&defType=component

Use the service by adding the component to a parent component's markup:

<c:PicklistService aura:id="picklistService"/>

Then, simply call the service from the parent's component controller like this:

// Getting picklist entries for Account.Industry field
component.find('picklistService').getEntries('Account', 'Industry', entries => {
    console.log(entries);
});

Entries are returned as an Array of JS Object:

[
    {
        "value": "Agriculture",
        "label": "Agriculture",
        "isDefaultValue": false
    },
    ...
]

Entries can directly be used in a lightning:combobox component:

<lightning:combobox name="values" label="Picklist entries" options="{!v.entries}"/>

Salesforce DX setup instructions

Deploy the sample application with the Salesforce CLI.

Sample application

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

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