? Integration with Platform Events

Shen Yifeng

salesforce enthusiast,sfdc developer, consultant

The power of JSforce

Node.js is the most popular Javascript choice for developers and is continuously expanding its base. It is powered by the Google V8 engine which adds the fuel to its already high performance. Here are some of its advantages: serverless and hardware free solution, microservices, scalability, reusability, graphQL, near real-time apps...... And JSforce is a isomorphic JavaScript Library utilizing Salesforce's API: It works both in browser and with Node.js. It supports REST API, Apex REST, Analytics API, Bulk API, Chatter API, Metadata API, Streaming API, Tooling API. Below I would like to take two examples to demo its integration with salesforce.

(1) Utilizing Metadata API

  • The most common way

Sometimes we want to mass update the profiles such as login ip ranges or login hours etc, below is the js code which update the ip range of all profiles. Although it is not beautiful but it works, you can refactor it using the async function and promise function.

var express        = require( 'express' );
var http           = require( 'http' );
var jsforce        = require('jsforce');

var app            = express();
app.set( 'port', process.env.PORT || 3001 );
app.get('/', function (req, res) {
  var records = [];
  conn.login(username, password, function(err, userInfo) {
  if (err) { return console.error(err); }
    var records = [];
    conn.query("SELECT Id, Name FROM Profile", function(err, result) {
    if (err) { return console.error(err); }
       console.log("total : " + result.totalSize);
       console.log("fetched : " + result.records.length);
       var recordsname;
         for (var i=0; i"
            conn.metadata.update('Profile', {
              fullName: record.Name,
             },function(err2, result2) {
             if (err2)

  • The Oauth2 way

But in production enviroment, it is so common that security token is not provided. In that case, how we can access salesforce org from the outside? Yes, salesforce has implemented the oauth 2.0 technique and which is called connected application in the platform. Look at the following pictures that I had executed using oauth2

(2) LWC apps both at local and on Heroku

In the latest Spring ’19 release, Salesforce has introduced the new Lightning Web Components (LWC) which is a new programming model for building Lightning components. By utilizing JSforce, we can create LWC apps outside salesforce but with a whole integration with it.

The folowing sample is from trailhead, base on JSforce, the app can interact with salesforce inside data.


Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. More than 164K Number of websites are using Nodejs now.

This post is crafted by myself.