Hello, friends in this session we are going to know about Jforce library in Node.Js. Jsforce (f.k.a. Node-Salesforce) is an isomorphic JavaScript Library utilizing Salesforce’s API: It works both in the browser and with Node.js.

Introduction:

In one of my previous project, I wanted to connect my node.js application to salesforce and pull data from Salesforce. I found a very useful library called js force.

Jsforce (f.k.a. Node-Salesforce) is an isomorphic JavaScript Library utilizing Salesforce’s API: It works both in the browser and with Node.js.

jsforce

It encapsulates the access to various APIs provided by Salesforce in asynchronous JavaScript function calls.
If you want to use jsforce in your node js application you need to install Jsforce as an API library using the following command.

npm install jsforce

After successful installation of Jsforce library, you need to add the following line of code.

var jsforce = require('jsforce');
var conn = new jsforce.Connection();

Let’s create a simple example of Jsforce using node js.

Example of Jsforce with Node.Js

1- Create a directory where you want to create your application.

2-  Navigate to the folder location.

3- Install Jsforce library using the following command.

npm install jsforce

4- Create a Js file called jsforce.js  or anything that you want. Write the following into the file.

var jsforce = require('jsforce');
var conn = new jsforce.Connection();
conn.login('YOUR-Salesforce-UserName','YOUR-Salesforc-Password+YOUR-Salesforce-SecurityToken, function(err, res) {
if (err) { return console.error(err); }
conn.query('SELECT Id, Name FROM Account', function(err, res) {
if (err) { return console.error(err); }
console.log(res);
});
});

Replace UserName, Password and Security Token with your Salesforce credentials.

5- Now run the following command to test your code.

Node jsforce.js

After running this command you will simply get the list of Account from your organization.

View More:

Conclusion:

I hope this session will help you to understand the Interaction of salesforce with Node.Js application. Please don’t hesitate to comment for any technical help.

Thank You.

Leave a Comment