Skip to content

Instantly share code, notes, and snippets.

@agentgill
Last active August 25, 2021 09:55
Show Gist options
  • Select an option

  • Save agentgill/0f61af702f9b3af5311910e53e92a3a3 to your computer and use it in GitHub Desktop.

Select an option

Save agentgill/0f61af702f9b3af5311910e53e92a3a3 to your computer and use it in GitHub Desktop.
Subscriber to Platform Event using JSForce
var jsforce = require("jsforce");
require("dotenv").config();
var username = process.env.SFDC_USER;
var password = process.env.SFDC_PWD;
var conn = new jsforce.Connection({ loginUrl: "https://login.salesforce.com" });
conn.login(username, password, function (err, userInfo) {
const replayId = 13475880;
const replayExt = new jsforce.StreamingExtension.Replay(
process.env.EVENT_TYPE,
replayId
);
const fayeClient = conn.streaming.createClient([replayExt]);
if (err) {
return console.log(err);
}
console.log("Connected to" + process.env.EVENT_TYPE);
const subscription = fayeClient.subscribe(
process.env.EVENT_TYPE,
(data) => {
console.log("topic received data", data);
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment