Newer Version Available
Generate Events Using REST
Use the Streaming Channel Push REST API resource to generate event notifications to
channel subscribers.
You’ll use Workbench to access REST API and send notifications. Workbench is a free, open source, community-supported tool (see the Help page in Workbench). Salesforce provides a hosted instance of Workbench for demonstration purposes only—Salesforce recommends that you do not use this hosted instance of Workbench to access data in a production database. If you want to use Workbench for your production database, you can download, host, and configure it using your own resources. You can download Workbench from https://github.com/forceworkbench/forceworkbench.
- In a browser, navigate to https://workbench.developerforce.com/login.php.
- For Environment, select Production.
- For API Version, select 53.0.
- Accept the terms of service and click Login with Salesforce.
- Once you successfully establish a connection to your database, you land on the Select page.
- Find the StreamingChannel ID by clicking and doing a SOQL query for SELECT Name, ID FROM StreamingChannel. Copy down the StreamingChannel ID for /u/notifications/ExampleUserChannel.
- Click .
- In the URL field, enter /services/data/v<API version>/sobjects/StreamingChannel/<Streaming Channel ID>/push, where v<API version> is v53.0 and <Streaming Channel ID> is the ID of the StreamingChannel you found in Step 6.
- Set the HTTP method by selecting POST. In Request Body, enter the JSON request body shown in “Example POST REST request body” below.
- With your Java subscriber client running, click Execute. This sends the event to all subscribers on the channel. You should receive the notification with the payload text in your Java client. The REST method response will indicate the number of subscribers the event was sent to (in this case, –1, because the event was set to broadcast to all subscribers).
You’ve successfully sent a notification to a subscriber using generic
streaming. Note that you can specify the list of subscribed users to send notifications
to instead of broadcasting to all subscribers. Also, you can use the GET method of the
Streaming Channel Push REST API resource to get a list of active subscribers to the
channel.
Example
Example POST REST request
body:
1{
2 "pushEvents": [
3 {
4 "payload": "Broadcast message to all subscribers",
5 "userIds": []
6 }
7 ]
8}