0

I am trying to subscribe to Salesforce Platform Events in my Developer Edition through AWS Lambda via Connected App(Using nforce SDK).

Code is as follows:

var AWS = require('aws-sdk'); //Importing aws-sdk, aws-sdk is node.js sdk for AWS
var nforce = require('nforce'); //Importing nforce, nforce is node.js REST API Wrapper for Salesforce

//Replace these values with your org-specific data - Start
var CLIENT_ID = 'SOME_ID'; //Retrieve from Connected App
var CLIENT_SECRET = 'SOME_SECRET'; //Retrieve from Connected App
var USER_NAME = 'SOME_USERNAME'; //Integration User Name
var USER_PASSWORD = 'SOME_PASSWORD'; //Integration User Password
var TOPIC = 'Won_Quote__e';//Event Name
var REPLAY_ID = -1; //Replay Value

//Replace these values with your org-specific data - End

//Make connection to connected App - Start 
var org = nforce.createConnection({
      clientId: CLIENT_ID, 
      clientSecret: CLIENT_SECRET, 
      redirectUri: 'http://localhost:3000/oauth/_callback',
      //apiVersion: 'v35.0',  // optional, defaults to current salesforce API version
      //environment: 'production',  // optional, salesforce 'sandbox' or 'production', production default
      mode: 'single' // optional, 'single' or 'multi' user mode, multi default
});
//Make Connection to connected App - End

// Authenticate single-user mode - Start
//Declare function as your exports handler, your function should export some thing to Lambda
exports.handler = function(event, context, callback) {
     // authenticate via oauth process to SFDC
    org.authenticate({ username: USER_NAME , password: USER_PASSWORD }, function(err, resp){
          // the oauth object was stored in the connection object
          if(!err) {
              console.log('Cached Token: ' + org.oauth.access_token); //We recieved oauth access token
          }else{
               console.log("Error authenticating to Salesforce, " + err); //There is some problem
          }

          //Initiate listener for listening to salesforce event bus
          var client = org.createStreamClient();

          //Subscribing to Channel for the event
          var accs = client.subscribe({topic:TOPIC, isEvent:true, retry: REPLAY_ID});

          //if Subscription fails, function will disconnect before this
          console.log("Subscription to " + TOPIC + " successful");
    });

}

I got a message in the Lamdba that Subscription is successful, following message, I can see in the logs:

console.log("Subscription to " + TOPIC + " successful");

But When I look at the Platform Event Object, subscriptions are not available.

Event Subscriptions not available

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.