Consider moving to Lightning Web Components. See the Retrieving Picklist Values Without Using Apex blog post and the sample LWC repository.
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
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}"/>
Deploy the sample application with the Salesforce CLI.
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.