Here's a quick proof of concept that shows how to subscribe to Platform Events. There are a few changes that you'd like to make prior to setting up and testing out your subscription.
- Log into your Salesforce org within the browser
- Update
baseUrl
in app.js to be your base instance URL appended with "/cometd/40.0" - Inspect the cookies for this site in your browser, and copy the value from the
sid
cookie; you'll set this as the value oftoken
in app.js - Navigate to your Platform Event in the Setup UI and copy the API name; you'll set this as the value of
platformEventName
in app.js
To ensure we have the appropriate node packages installed, navigate to this project's directory and run npm install
. Upon finishing the installation of cometd and cometd-nodejs-client.
When this finishes, run node app.js
to subscribe to the platform event. If there are any errors, these will be dumped into the terminal output, otherwise terminal should display nothing until an event is created.
Create a platform event using process builder, Apex, or the API and observe the output in the terminal.