Skip to content

Example on how to connect the NodeJS CometD client to a Salesforce Org to subscribe to Platform Events

Notifications You must be signed in to change notification settings

johndturn/cometd-node-example

Repository files navigation

NodeJS CometD <> Salesforce Example

Built with ❤️  by John Turner

Small POC of subscribing to Salesforce Platform Events via the NodeJS CometD library.

Utilizes the OAuth 2.0 JWT Bearer flow for authenticating to Salesforce.

Requirements

  • Node 16+ & NPM
  • OpenSSL
  • Access to a Salesforce Org with a Platform Event created

Setup

Note: The following (at this time) has been tested on a macOS machine. I can't vouch for the Certificate Generation section working on Linux or Windows environments running WSL.

Certificate Generation

  1. Clone this repo to your local machine
  2. Duplicate ./scripts/generate-certificate.sh.example into ./scripts/generate-certificate.sh
  3. Fill in your correct information in generate-certificate.sh
  4. Run cd scripts/ && chmod +x generate-certificate.sh && cd ..
  5. Generate the certificate: npm run create-cert

Connected App Setup

Example Connected App Setup

Screen shot of Connected App Setup

  1. Set up Connected App with the .crt that was generated via the shell script
  2. Navigate to Setup > Manage Connected Apps > Your newly-created App
  3. Edit the app and switch the App's "Permitted Users" option to Admin approved users are pre-authorized
  4. Create a new Permission Set that allows access to this Connected App
  5. Assign your user to the Permission Set

Local Config Setup

  1. Duplicate config.json.example into config.json
  2. Set up the config.json according to the information from your Connected App and SFDC instance
  3. Install dependencies npm i
  4. Run: npm run start

Further Learning

About

Example on how to connect the NodeJS CometD client to a Salesforce Org to subscribe to Platform Events

Topics

Resources

Stars

Watchers

Forks