Define a View

A view is composed of components that display in a Slack surface: a home tab, message, or modal. Define a view in a .view file, which is YAML that describes the components that make up the view.

In a Slack runtime environment, a view translates to blocks. In your SFDX project, a view lives in the force-app/main/default/viewdefinitions folder. For more information, see the ViewDefinition Tooling API object.

Components in a view can handle events such as a button click. See Interactive Components. You can also bind data to a view using expressions and data providers.

Views are not cached. If your view fails to render, check your view definition and YAML indentation.

Note

View Definition Keys 

KeyTypeDescription
descriptionStringA description of this view. Not used in code.
schemaObjectThe input properties for this view.
schema.propertiesObjectA map of property names to their schema.
schema.properties.typeStringThe type of the property value. One of these values: string, boolean, number, list, map, or null.
schema.properties.requiredBooleanSpecifies whether the property is required. If true, defaultValue is ignored.
schema.properties.defaultValueStringThe default value to use if one isn’t provided and required is false. Must be a literal value.
dataprovidersObjectThe data sources for this view. A map of data provider keys to data providers.
dataproviders.definitionStringRequired. The name of the data provider in the format apex__MyClassName.getMyMethodName or apex__MyNamespace.MyClassName.getMyMethodName.
dataproviders.propertiesObjectThe input properties for this data provider. A map of property names to either literal values or string expressions.
componentsArrayRequired. The components that make up this view.
components.definitionStringRequired. The name of the component definition.
components.nameString, ExpressionThe name to uniquely identify the component within the view.
components.visibilityBoolean, ExpressionIndicates whether the component is shown or hidden. If this property isn’t present or it evaluates to true, the component is shown. Otherwise, the component is hidden.
components.propertiesObjectThe properties of this component. A map of property names to literal values or expressions.
components.componentsArrayThe child components of this component.
regionsArrayThe regions for this view component. Not currently supported.

Some components can handle an event like onclick or onchange, which is also configured in the view definition. See the Component Reference.

Tip

Examples 

Use these examples to build your own views.

Display a Message in a Modal 

This view definition displays a message in a modal. The modal component contains a section component. The view has a title and message property, which is bound to the modal’s title and section’s text property each.

1description: "Display a message in a modal"
2schema:
3  properties:
4    title:
5      type: string
6      required: true
7    message:
8      type: string
9      required: true
10components:
11  - definition: modal
12    properties:
13      title: "{!view.properties.title}"
14    components:
15      - definition: section
16        properties:
17          text: "{!view.properties.message}"

Create a Record 

This view definition displays a modal for creating a record. The modal contains a section component with an actions component, which has a button to create the record. When clicked, the button calls the createOpportunity Apex class.

1description: "Trigger an Apex block action."
2components:
3  - definition: modal
4    properties:
5      title: "Create Record"
6    components:
7      - definition: section
8        properties:
9          text: "Which object do you want to create a record for?"
10      - definition: actions
11        name: "apex_actions"
12        components:
13          - definition: button
14            properties:
15              label: "Create Opportunity"
16              style: "primary"
17              name: "apex_action"
18            events:
19              onclick:
20                #createOpportunity must exist in the consumer org as an apex class that implements Slack.Action
21                definition: "apex__action__createOpportunity"
22                properties:
23                  objectApiName: "Opportunity"

Submit a Record 

This view definition creates an opportunity record when the submit button is clicked. When clicked, the button calls the submitOpportunity Apex class. The modal contains input fields with placeholders, including a select component with a list of options.

1description: "Creates an opportunity record by triggering an Apex action on submission."
2components:
3  - definition: modal
4    properties:
5      title: "Create Opportunity"
6      submitLabel: "Create"
7    events:
8      onsubmit:
9        #submitOpportunity must exist in the consumer org as an Apex class that implements Slack.ActionDispatcher
10        definition: "apex__action__submitOpportunity"
11    components:
12      - definition: input
13        properties:
14          label: "Name" # label is the field label
15          required: true
16        components:
17          - definition: textInput
18            properties:
19              name: "Name" # name should be FieldApiName
20              placeholder: "Name"
21              value: "{!view.properties.name}"
22      - definition: input
23        properties:
24          label: "Amount"
25          required: true
26        components:
27          - definition: textInput
28            properties:
29              name: "Amount"
30              placeholder: "175000"
31      - definition: input
32        properties:
33          label: "Stage"
34          required: true
35        components:
36          - definition: select
37            properties:
38              name: "StageName"
39              value: ""
40              placeholder: "Select a stage."
41              options:
42                - identifier: "Prospecting"
43                  label: "Prospecting"
44                - identifier: "Qualification"
45                  label: "Qualification"
46                - identifier: "Needs Analysis"
47                  label: "Needs Analysis"
48                - identifier: "Value Proposition"
49                  label: "Value Proposition"
50                - identifier: "Id. Decision Makers"
51                  label: "Id. Decision Makers"
52                - identifier: "Perception Analysis"
53                  label: "Perception Analysis"
54                - identifier: "Proposal/Price Quote"
55                  label: "Proposal/Price Quote"
56                - identifier: "Negotiation/Review"
57                  label: "Negotiation/Review"
58                - identifier: "Closed Won"
59                  label: "Closed Won"
60                - identifier: "Closed Lost"
61                  label: "Closed Lost"
62      - definition: input
63        properties:
64          label: "Close Date"
65          required: true
66        components:
67          - definition: datepicker
68            properties:
69              name: "CloseDate"
70              placeholder: "YYYY-MM-DD"

Beta Feature

This feature is not generally available. It is not part of your purchased Services. This feature is subject to change, may be discontinued with no notice at any time in SFDC’s sole discretion, and SFDC may never make this feature generally available. Make your purchase decisions only on the basis of generally available products and features. This feature is made available on an AS IS basis and use of this feature is at your sole risk.