0

When I run my program using nForce to connect to the client I get this error...

400::The replayId for channel {/topic/mypushtopic} wasn't found using the " + 'provided replay ID map {{}}. Ensure that the channel name you provided in ' + 'the replay map is valid and matches the channel name used for subscribing.

When I run in the Workbench it returns the JSON fine, but when running in node it is asking for replayID Map? I am also subscribed to the correct pushTopic. Help Please. Thanks.

Here is my code.

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var config = require('./config.js');
var nforce = require('nforce');

var routes = require('./routes/index');

var app = express();
var server = require('http').Server(app);
// attach socket.io and listen
var io = require('socket.io')(server);
// get a reference to the socket once a client connects
var socket = io.sockets.on('connection', function (socket) { });

var DEFAULT_REPLAY_ID = -1;


var org = nforce.createConnection({   clientId: config.CLIENT_ID,   clientSecret: config.CLIENT_SECRET,   redirectUri: config.CALLBACK_URL
+ '/oauth/_callback',   autoRefresh: true,   environment: 'production',   apiVersion: 'v44.0',   mode: 'single' });


org.authenticate({ username: config.USERNAME, password: config.PASSWORD }, function(err, oauth) {

  if(err) return console.log(err);
  if(!err) {
    console.log('*** Successfully connected to Salesforce ***');
// add any logic to perform after login
  }

  const client = org.createStreamClient();

  const sub = client.subscribe({ topic: 'AccountUpdates' });

  //subscribe to a pushtopic
 //var str = org.stream({ topic: config.PUSH_TOPIC, oauth: oauth });

client.on('connect', function () {
    console.log('streaming client transport: up');
  });

  client.on('disconnect', function (data) {
console.log('streaming disconnect: ' + data.reason);
console.log('disconnect data', data);
  });

  sub.on('connect', function () {
console.log('connected to topic: ' + sub.getTopic());   });

  sub.on('error', function (error) {
console.log('error: ' + error);
sub.cancel();
client.disconnect();   });

  sub.on('data', function (data) {
    console.log(data);
    console.log('current replay id: ' + sub.getReplayId())   });


});

app.set('port', process.env.PORT || 3001);

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hjs');

// uncomment after placing your favicon in /public
//app.use(favicon(__dirname + '/public/favicon.ico'));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err); });

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
    res.status(err.status || 500);
    res.render('error', {
        message: err.message,
        error: err
    });
}); }

// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
    message: err.message,
    error: {}
}); });


server.listen(app.get('port'), function() {   console.log('Express server listening on port %d in %s mode', app.get('port'), app.get('env')); });

module.exports = app;
0

From reading nforce documentation, it appears you only need to add replayId: -2 in the parameter object when you called client.subscribe. -2 means all saved messages, and -1 means new messages only.

|improve this answer|||||
-1

Just use python and save yourself the time. It has various libraries that utilize the streaming API. Very easy to use.

|improve this answer|||||
  • Please add at least one specific example or this answer is likely to be deleted by the community. – Adrian Larson Aug 26 '19 at 20:40

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.