Demonstrates how to use List View Describe information to query for sobject records and display them in a Lightning Component using lightning:datatable.
The UI-API also
has ability to retrieve Records and some List View Metadata, but it does not return the
data type of each field to know if a field is text, phone, number, etc. which is important
when specifying the columns of the <lightning:datatable>
component.
- Clone this repository
git clone https://github.com/DouglasCAyers/sfdx-listview-datatable-example.git
cd sfdx-listview-datatable-example
- Use Salesforce DX CLI to create a scratch org and push the source to it
sfdx force:org:create -f config/project-scratch-def.json -a lvdt -s
sfdx force:source:push -w 10
sfdx force:org:open
- Generate a password for the scratch org, you will need your org's
username
andpassword
in the next step.
sfdx force:user:password:generate
-
Follow these instructions to create the necessary Connected App, Auth. Provider, and Named Credential to allow Apex used by a Lightning Component to invoke Salesforce REST API.
-
Create some test records for an object and create a list view for them. Note the list view filter id in the browser's address bar (e.g.
00Bxxxxxxxxxxxx
) -
Use App Builder to add the custom component
ListViewDataTable
to a Lightning Page (e.g. a Home Page or Record Page). Specify theNamed Credential
andList View ID
design attributes in App Builder.
Inspired by Peter Churchill who asked via #askforce on Twitter:
In Classic, I can use getListViewOptions with a Standard Set Controller to display list views in a dropdown, and then get the records for that list using SetFilterId. Is there any equivalent in LEX components, or an alternative that achieves same result?
This project serves as a quick proof-of-concept and as-such does not provide any unit tests. It is for educational purposes.