There are many ways that Salesforce can communicate with external systems. One of the most powerful is through Platform Events, allowing for complex and robust event-driven architectures to be built with mostly clicks, not code. However, when it comes to external systems listening for those events, usually some programmatic development is needed.
In this small, developer-focused post, I’ll cover some learnings regarding CometD clients, deployments to Windows Server, and how to set up Salesforce Connected Apps.
CometD & Windows
In 2022, just as the more robust, gRPC-based Pub/Sub API was making its way into general availability, we worked with a client that needed to have an external service listen for Platform Events emitted from their Salesforce instance. They asked us to write a small Node.js-based client as a listener, and deploy it to a Windows 2019 server running in their Azure instance. Given the timing of the Pub/Sub API, we opted for using the CometD-based Streaming API, and got to work!
As I worked through the various issues that we faced, I noted the steps needed to run this client, and eventually published a step-by-step guide on my personal blog, which can be found here. Feel free to review it there.
Salesforce Connected App Setup
Building the CometD client is one thing, but authenticating to the Salesforce APIs is an entirely separate beast. The recommendation from Salesforce for server-to-server communications via API (at the time of writing this) is the JWT Bearer Token OAuth2.0 flow, which can be tricky to set up if you haven’t done it before. We put together a small open-source Github repo that includes example code for a lightweight Node-based CometD client. More importantly, this repo contains instructions and screen shots covering how to create a correctly-configured Salesforce Connected App, including a shell script for generating the certificate needed to enable the JWT-based OAuth2.0 flow. There is also a small lib file for connecting to the Salesforce APIs to retrieve an access token that you can turn around and use for standard REST API calls.
Conclusion
Are you facing an issue connecting one or more systems with Salesforce? At SOLVD, we’re passionate about providing robust solutions that empower Salesforce users and connect your critical business applications. If you’ve found this content helpful or would like to talk more about development in general, feel free to reach out to SOLVD here to learn more about our consulting services.