Work with Views

The following are Apex classes for the Slack views API methods.

ViewContext Class 

Contains information about a view.

ViewContext Methods 

ViewContext has the following methods.

getId() 

The ID of the view.

Signature

1public String getId()

Return Value

Type: String

getHash() 

A unique value that’s optionally accepted in views.update and views.publish API calls. When provided to those APIs, the hash is validated such that only the most recent view can be updated. This should be used to ensure the correct view is being updated when updates are happening asynchronously.

Signature

1public String getHash()

Return Value

Type: String


ViewReference Class 

Represents a view definition. This class provides access to ViewDefinition records where the targetType is slack.

Usage

1ViewReference myViewReference = Slack.View.namespace.name; // returns a ViewReference
2myViewReference.setParameter("recordId", "001.........");
3Slack.App.myApp.getBotClient(...).postMessage(myViewReference);

ViewReference Methods 

The following are methods for ViewReference.

setParameter(name, value) 

Sets the name and value of the view definition.

Signature

1public void setParameter(String name, Object value)

Parameters

name Type: String

The name of the view definition.

value

Type: Object

Return Value

Type: void


ViewsOpenRequest Class 

Sends a request to open a view for a user.

Usage

See Slack’s view.open method.

ViewsOpenRequest Methods 

The following are methods for ViewsOpenRequest.

builder() 

Builds a request object that’s used when executing the API call.

Signature

1public static Slack.ViewsOpenRequest.Builder builder()

Return Value

Type: Slack.ViewsOpenRequest.Builder

ViewsOpenRequest.Builder Class 

Contains methods to build an instance of the Slack.ViewsOpenRequest class.

A Builder object is obtained by invoking one of the ViewsOpenRequest.builder methods defined by the ViewsOpenRequest class.

ViewsOpenRequest.Builder Methods 

The following are methods for ViewsOpenRequest.Builder.

build() 

Required. Returns an instance of Slack.ViewsOpenRequest.

Signature

1public Slack.ViewsOpenRequest build()

Return Value

Type: Slack.ViewsOpenRequest

triggerId(triggerId) 

Required. Exchanges a trigger to post to the user.

Signature

1public Slack.ViewsOpenRequest.Builder triggerId(String triggerId)

Parameters

triggerId

Type: String

Return Value

Type: Slack.ViewsOpenRequest.Builder

view(view) 

Required. A view payload in the form of a JSON-encoded string.

Signature

1public Slack.ViewsOpenRequest.Builder view(Slack.ModalView view)

Parameters

view

Type: Slack.ModalView

Return Value

Type: Slack.ViewsOpenRequest.Builder

ViewsOpenResponse Class 

Opens a view for a user.

Usage

See Slack’s view.open method.

ViewsOpenResponse Methods 

This class contains standard response methods.

The following are methods for ViewsOpenResponse.

getRenderedView() 

Signature

1public Slack.View getRenderedView()

Return Value

Type: Slack.View

getResponseMetadata() 

Signature

1public Slack.ErrorResponseMetadata getResponseMetadata()

Return Value

Type: Slack.ErrorResponseMetadata

setResponseMetadata(responseMetadata) 

Signature

1public void setResponseMetadata(Slack.ErrorResponseMetadata responseMetadata)

Parameters

responseMetadata

Type: Slack.ErrorResponseMetadata

Return Value

Type: void

ViewsPublishRequest Class 

Sends a request to publish a static view for a user.

Usage

See Slack’s view.publish method.

ViewsPublishRequest Methods 

The following are methods for ViewsPublishRequest.

builder() 

Builds a request object that’s used when executing the API call.

Signature

1public static Slack.ViewsPublishRequest.Builder builder()

ViewsPublishRequest.Builder Class 

Contains methods to build an instance of the Slack.ViewsPublishedRequest class.

A Builder object is obtained by invoking one of the ViewsPublishRequest.Builder methods defined by the ViewsPublishRequest class.

ViewsPublishRequest.Builder Methods 

The following are methods for ViewsPublishRequest.Builder. These methods are optional unless specified otherwise.

build() 

Required. Returns an instance of the Slack.ViewsPublishRequest object.

Signature

1public Slack.ViewsPublishRequest build()

Return Value

Type: Slack.ViewsPublishRequest

hash(hash) 

A string that represents view state to protect against possible race conditions.

Signature

1public Slack.ViewsPublishRequest.Builder hash(String hash)

Parameters

hash

Type: String

Return Value

Type: Slack.ViewsPublishRequest.Builder

userId(userId) 

Required. The ID of the user you want to publish a view to.

Signature

1public Slack.ViewsPublishRequest.Builder userId(String userId)

Parameters

userId

Type: String

Return Value

Type: Slack.ViewsPublishRequest.Builder

view(view) 

Required. A JSON-encoded string that contains the view payload.

Signature

1public Slack.ViewsPublishRequest.Builder view(Slack.HomeView view)

Parameters

view

Type: Type: Slack.HomeView

Return Value

Type: Slack.ViewsPublishRequest.Builder

HomeView Class 

Build views for the App Home page.

Usage

HomeView enables you to build a view for your App Home page, and publish the view when an action is dispatched.

1Slack.HomeView homeView = new Slack.HomeView.builder()
2    .viewReference(viewReference)
3    .build();
4
5Slack.ViewsPublishRequest req = new Slack.ViewsPublishRequest.builder()
6    .userId(context.getUserId())
7    .view(homeView)
8    .build();
9
10Slack.ViewsPublishResponse response = botClient.viewsPublish(req);
11
12if (response.getError() != null) {
13    System.debug(response.getError());
14}

You can also publish the view in response to a slash command. See ChatPostMessageRequest.

HomeView Methods 

The following are methods for HomeView.

builder() 

Builds an object which is used when executing the API call.

Signature

1public static Slack.HomeView.Builder builder()

Return Value

Type: Slack.HomeView.Builder

HomeView.Builder Class 

Contains methods to build an instance of the Slack.HomeView class.

A Builder object is obtained by invoking one of the HomeView.builder methods defined by the ViewsOpenRequest class.

HomeView.Builder Methods 

The following are methods for HomeView.Builder.

build() 

Signature

1public Slack.HomeView build()

Return Value

Type: Slack.HomeView

externalId(externalId) 

Signature

1public Slack.HomeView.Builder externalId(String externalId)

Parameters

externalId

Type: String

Return Value

Type: Slack.HomeView.Builder

viewReference(viewReference) 

Signature

1public Slack.HomeView.Builder viewReference(Slack.ViewReference viewReference)

Parameters

viewReference

Type: Slack.ViewReference

Return Value

Type: Slack.HomeView.Builder

ViewsPublishResponse Class 

Publish a static view for a user.

Usage

See Slack’s view.publish method.

ViewsPublishResponse Methods 

This class contains standard response methods.

The following are methods for ViewsPublishResponse.

getResponseMetadata() 

Signature

1public Slack.ErrorResponseMetadata getResponseMetadata()

Return Value

Type: Slack.ErrorResponseMetadata

setResponseMetadata(responseMetadata) 

Signature

1public void setResponseMetadata(Slack.ErrorResponseMetadata responseMetadata)

Parameters

responseMetadata

Type: Slack.ErrorResponseMetadata

Return Value

Type: void

ViewsPushRequest Class 

Sends a request to push a view onto the stack of a root view.

Usage

See Slack’s views.push method.

ViewsPushRequest Methods 

The following are methods for ViewsPushRequest.

builder() 

Builds a request object that’s used when executing the API call.

Signature

1public static Slack.ViewsPushRequest.Builder builder()

Return Value

Type: Slack.ViewsPushRequest.Builder

ViewsPushRequest.Builder Class 

Contains methods to build an instance of the Slack.ViewsPushRequest class.

A Builder object is obtained by invoking one of the ViewsPushRequest.Builder methods defined by the ViewsPushRequest class.

ViewsPushRequest.Builder Methods 

The following are methods for ViewsPushRequest.Builder.

build() 

Required. Returns an instance of Slack.ViewsPushRequest.

Signature

public Slack.ViewsPushRequest build()

Return Value

Type: Slack.ViewsPushRequest

triggerId(triggerId) 

Required. Exchanges a trigger to post to the user.

Signature

1public Slack.ViewsPushRequest.Builder triggerId(String triggerId)

Parameters

triggerId

Type: String

Return Value

Type: Slack.ViewsPushRequest.Builder

view(view) 

Required. A view payload in the form of a JSON-encoded string.

Signature

1public Slack.ViewsPushRequest.Builder view(Slack.ModalView view)

Parameters

view

Type: Slack.ModalView

Return Value

Type: Slack.ViewsPushRequest.Builder

ViewsPushResponse Class 

Pushes a view onto the stack of a root view.

Usage

See Slack’s views.push method.

ViewsPushResponse Methods 

This class contains standard response methods.

The following are methods for ViewsPushResponse.

getResponseMetadata() 

Signature

1public Slack.ErrorResponseMetadata getResponseMetadata()

Return Value

Type: Slack.ErrorResponseMetadata

setResponseMetadata(responseMetadata) 

Signature

1public void setResponseMetadata(Slack.ErrorResponseMetadata responseMetadata)

Parameters

responseMetadata

Type: Slack.ErrorResponseMetadata

Return Value

Type: void

ViewsUpdateRequest Class 

Sends a request to update an existing view.

Usage

See Slack’s views.update method.

ViewsUpdateRequest Methods 

The following are methods for ViewsUpdateRequest.

builder() 

Builds a request object that’s used when executing the API call.

Signature

1public static Slack.ViewsUpdateRequest.Builder builder()

Return Value

Type: Slack.ViewsUpdateRequest.Builder

ViewsUpdateRequest.Builder Class 

Contains methods to build an instance of the Slack.ViewsUpdateRequest class.

A Builder object is obtained by invoking one of the ViewsUpdateRequest.Builder methods defined by the ViewsUpdateRequest class.

ViewsUpdateRequest.Builder Methods 

The following are methods for ViewsUpdateRequest.Builder. These methods are optional unless specified otherwise.

build() 

Required. Returns an instance of Slack.ViewsUpdateRequest.

Signature

1public Slack.ViewsUpdateRequest build()

Return Value

Type: Slack.ViewsUpdateRequest

externalId(externalId) 

Required if view(view) is not provided. A unique identifier of the view set by the developer. Must be unique for all views on a team. Max length of 255 characters.

Signature

1public Slack.ViewsUpdateRequest.Builder externalId(String externalId)

Parameters

externalId

Type: String

Return Value

Type: Slack.ViewsUpdateRequest.Builder

hash(hash) 

A string that represents view state to protect against possible race conditions.

Signature

1public Slack.ViewsUpdateRequest.Builder hash(String hash)

Parameters

hash

Type: String

Return Value

Type: Slack.ViewsUpdateRequest.Builder

view(view) 

Required if externalId(externalId) is not provided. A view object in the format of a JSON-encoded string.

Signature

1public Slack.ViewsUpdateRequest.Builder view(Slack.ModalView view)

Parameters

view

Type: Slack.ModalView

Return Value

Type: Slack.ViewsUpdateRequest.Builder

viewId(viewId) 

A unique identifier of the view to be updated. Required if the external ID is not provided.

Signature

1public Slack.ViewsUpdateRequest.Builder viewId(String viewId)

Parameters

viewId

Type: String

Return Value

Type: Slack.ViewsUpdateRequest.Builder

ViewsUpdateResponse Class 

Updates an existing view.

Usage

See Slack’s views.update method.

ViewsUpdateResponse Methods 

This class contains standard response methods.

The following are methods for ViewsUpdateResponse.

getRenderedView() 

Signature

1public Slack.View getRenderedView()

Return Value

Type: Slack.View

getResponseMetadata() 

Signature

1public Slack.ErrorResponseMetadata getResponseMetadata()

Return Value

Type: Slack.ErrorResponseMetadata

setResponseMetadata(responseMetadata) 

Signature

1public void setResponseMetadata(Slack.ErrorResponseMetadata responseMetadata)

Parameters

responseMetadata

Type: Slack.ErrorResponseMetadata

Return Value

Type: void

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.