function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
gtuerk_greensaasgtuerk_greensaas 

JSForce Platform Event Subscription

I have a node.js application that uses JSForce and subscribes to platform events.  The app is working fine in production (on Winter '20) but my sandbox that was refreshed for Spring '20 doesn't appear to be picking up new platform events that are published to the EventBus in APEX.  Is there a known issue with Platform events that is being worked out?
Alain CabonAlain Cabon
@gtuerk_greensaas

Did you change the version? ( version: '48.0' )
 
var jsforce = require('jsforce'),
    util = require('util'),
    fs = require('fs');

var username = '<your username>';
var password = '<your password>';

var conn = new jsforce.Connection({
    loginUrl: 'https://login.salesforce.com',
    version: '48.0',
});

conn.login(username, password, function (err, userInfo) {
    console.log('>login');
    if (err) {
        return console.error(err);
    }
    console.log('token:' + conn.accessToken);
    console.log('url:' + conn.instanceUrl);
    // logged in user property
    console.log("User ID: " + userInfo.id);
    console.log("Org ID: " + userInfo.organizationId);
  
    conn.streaming.topic("/event/AccountChangeEvent").subscribe(function (message) {
        //var buildingId = message.payload.Building_ID__c;
        console.log("payload:", message.payload);
    });

    conn.streaming.topic("/event/Building_Created__e").subscribe(function (message) {
        var buildingId = message.payload.Building_ID__c;
        console.log("Building ID", buildingId);
    });
});

let i = 0;
setInterval(() => {
    // console.log('Infinite Loop Test interval n:', i++);
}, 2000)
console.log('end');
 

Anonymous window (developer console):
// Create an instance of the event and store it in the newsEvent variable
Building_Created__e newsEvent = new Building_Created__e(Building_ID__c = '123456481450');
// Call method to publish events
Database.SaveResult sr = EventBus.publish(newsEvent);
// Inspect publishing result 
if (sr.isSuccess()) {
      System.debug('Successfully published event.');
} else {
    for(Database.Error err : sr.getErrors()) {
    System.debug('Error returned: ' +
              err.getStatusCode() +
              ' - ' +
              err.getMessage());
    }
}
Result:
Building ID 123456481450

Alain
 
Alain CabonAlain Cabon

"jsforce": "^1.9.3",
{
  "dependencies": {
    ...
    "jsforce": "^1.9.3",
    ...
  }
}
package.json
 
gtuerk_greensaasgtuerk_greensaas
Thanks for the answer!  I installed the latest jsforce 1.9.3 to no avail.  We've not been specifying the version in our connection instantiation in the past and I'm loath to do so. When I tried to change the API version I received a puke from jsforce 

Error: UNSUPPORTED_API_VERSION: Invalid Api version specified on URL
    at C:\Users\gtuer\ScratchPad\Quote2CashMiddleware\node_modules\jsforce\lib\connection.js:1365:13 
Alain CabonAlain Cabon
My tests:

Winter 20' :   version: '48.0': Error: UNSUPPORTED_API_VERSION;   version: '47.0' : no error and messages caught by jsforce ( 1.9.3 )

Spring 20' :  version: '48.0':  no error and messages caught by jsforce ( 1.9.3 ) ;   version: '47.0' : no error but NO messages caught by jsforce ( 1.9.3 ) (it is your big problem currently, no error but all the message are lost)

You have opened a question for the issues of jsforce, wait and see.

 
Alain CabonAlain Cabon
By default, the version of Salesforce used by jsforce should be the higher one but that is not the case.

The upgrade of jsforce was not mandatory for each version of Salesforce but here that seems the case.
 
gtuerk_greensaasgtuerk_greensaas
Alain - thanks again for your replies here.  I did indeed open a ticket with jsforce but nobody seems to have taken notice (yet) or the problem is only specific to my client orgs.  I'll keep this ticket open until the jsforce ticket is addressed one way or the other