从Node.js订阅SalesForce主题时出错

时间:2019-03-18 10:53:12

标签: javascript node.js salesforce publish-subscribe jsforce

我正在尝试使用the documentation of JSForce中提供的代码从Node.js服务器订阅SalesForce主题:

conn.streaming.topic("InvoiceStatementUpdates").subscribe(function(message) {
  console.log('Event Type : ' + message.event.type);
  console.log('Event Created : ' + message.event.createdDate);
  console.log('Object Id : ' + message.sobject.Id);
});

但是,我遇到了一个错误location is not defined

[1552904103100] ERROR (13143 on myuser): location is not defined
    ReferenceError: location is not defined
        at Object.parse (/home/myuser/projects/my-project/node_modules/faye/src/util/uri.js:36:36)
        at klass.initialize (/home/myuser/projects/my-project/node_modules/faye/src/protocol/dispatcher.js:21:28)
        at klass (/home/myuser/projects/my-project/node_modules/faye/src/util/class.js:13:28)
        at Function.Dispatcher.create (/home/myuser/projects/my-project/node_modules/faye/src/protocol/dispatcher.js:179:10)
        at klass.initialize (/home/myuser/projects/my-project/node_modules/faye/src/protocol/client.js:44:35)
        at klass (/home/myuser/projects/my-project/node_modules/faye/src/util/class.js:13:28)
        at Streaming._createClient (/home/myuser/projects/my-project/node_modules/jsforce/lib/api/streaming.js:127:20)
        at Streaming._getFayeClient (/home/myuser/projects/my-project/node_modules/jsforce/lib/api/streaming.js:148:42)
        at Streaming.subscribe (/home/myuser/projects/my-project/node_modules/jsforce/lib/api/streaming.js:185:25)
        at Topic.subscribe (/home/myuser/projects/my-project/node_modules/jsforce/lib/api/streaming.js:41:26)

深入研究问题发现a comment in Github指出faye 是JSForce的直接依赖项,只能在浏览器应用程序中使用。但是,JSForce有望在客户端和服务器端都能工作。

任何关于为什么会发生这种情况的想法将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:0)

我终于解决了在尝试使用login()函数之前进行显式streaming调用的问题。