Implement a Data Provider

A data provider is a reference to a source of data. It's implemented as a function within an Apex class.

To pull data into a view, bind the view to a data provider. To reference the data throughout a view, use an expression.

You can use these data types for input and output in Apex methods.

Data TypeDescriptionExamples
PrimitiveBoolean, Date, DateTime, Decimal, Double, Integer, Long, and String- Primitive Input and Primitive Output
- Primitive Input and List<Primitive> Output
sObjectA row of data declared using the SOAP API name of the object. Both standard and custom objects are supported.- Standard Object Input and List Output
- Custom Object Output
- List<sObject> Output
- Map with Contact List Output
ApexAn instance of an Apex classApex Class Output
CollectionA list, set, or map- Standard Object Input and List Output
-List<sObject> Output
- Primitive Input and List<Primitive> Output
- Map with Contact List Output

To bind a data provider to a component, follow this syntax for the definition value.

For example:

The arguments passed to the Apex method are specified as properties to the data provider. The property key must match the name of the parameter in the Apex method signature.

The Select component uses the dataproviders property to bind a data provider to the view.

To create a data provider for a Select component, construct a List<Slack.Option> or List<Slack.OptionGroup> for your view definition.

The External Select component uses the datasource property to bind a data provider to the view. For the External Select component, your Apex methods must follow certain method signature restrictions.

  • Must have a String value as the first parameter in addition to any other parameters already present.
  • Must return Slack.OptionDataResponse. Construct Slack.OptionDataResponse with List<Slack.OptionGroup> or List<Slack.Option>. All items in the same Slack.OptionDataResponse must be of the same type.

Constructing a Slack.OptionDataResponse with a combination of Slack.Option and Slack.OptionGroup isn’t supported.

The optional value parameter provides the input string entered into the select component that's used to perform the lookup. The value you provide preselects an option from the options identifier or from your data provider.

See more examples.

These examples show you how to create a data provider with Apex data types.

Apex method:

View:

Apex method:

View:

Apex method:

View:

Apex method:

View:

Apex method:

View:

Apex method:

View:

Apex method:

View:

This example is from view_contact.view in the sample app.

Apex data provider using List<Slack.Option> and returning Slack.OptionDataResponse:

Apex data provider using List<Slack.OptionGroup> and returning Slack.OptionDataResponse:

View:

This example is from create_opportunity.view in the sample app.