For example, let’s say you’re creating a component for the Home page to display a custom Company Announcement record. You can use an Apex class to put the titles of all Company Announcement records in a picklist in the component’s properties in the Lightning App Builder. Then, when admins add the component to a Home page, they can easily select the appropriate announcement to place on the page.
Here’s a simple example.
global class MyCustomPickList extends VisualEditor.DynamicPickList{ global override VisualEditor.DataRow getDefaultValue(){ VisualEditor.DataRow defaultValue = new VisualEditor.DataRow('red', 'RED'); return defaultValue; } global override VisualEditor.DynamicPickListRows getValues() { VisualEditor.DataRow value1 = new VisualEditor.DataRow('red', 'RED'); VisualEditor.DataRow value2 = new VisualEditor.DataRow('yellow', 'YELLOW'); VisualEditor.DynamicPickListRows myValues = new VisualEditor.DynamicPickListRows(); myValues.addRow(value1); myValues.addRow(value2); return myValues; } }
For more information on the VisualEditor.DynamicPickList abstract class, see the Apex Developer Guide.
To specify an Apex class as a datasource in an existing component, add the datasource property to the attribute with a value consisting of the Apex namespace and Apex class name.