Develop Salesforce apps with JavaScript,
whether it's running on server or web browser.

Download View on GitHub

Setup

$ npm install jsforce

Example

var jsforce = require('jsforce');
var conn = new jsforce.Connection();
conn.login('username@domain.com', 'password', 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);
  });
});

Example

<!DOCTYPE html>
<html>
<head>
  <script src="//cdnjs.cloudflare.com/ajax/libs/jsforce/1.3.1/jsforce.min.js"></script>
  <script>
jsforce.browser.init({
  clientId: '[ your Salesforce OAuth2 ClientID is here ]',
  redirectUri: '[ your Salesforce registered redirect URI is here ]'
});
jsforce.browser.on('connect', function(conn) {
  conn.query('SELECT Id, Name FROM Account', function(err, res) {
    if (err) { return console.error(err); }
    console.log(res);
  });
});
  </script>
</head>
<body>
  <button onclick="javascript:jsforce.browser.login();">Login</button>
</body>
</html>

Example

<apex:page docType="html-5.0" showHeader="false">
  <apex:includeScript value="{!URLFOR($Resource.JSforce)}" />
  <script>
var conn = new jsforce.Connection({ accessToken: '{!$API.Session_Id}' });
conn.query('SELECT Id, Name FROM Account', function(err, res) {
  if (err) { return console.error(err); }
  console.log(res);
});
  </script>
</apex:page>

Example

<!DOCTYPE html>
<html>
<head>
  <meta id="sf-canvas-signed-request" content="<%= verifiedSignedRequestJSON %>" />
  <script src="https://login.salesforce.com/canvas/sdk/js/31.0/canvas-all.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/jsforce/1.3.1/jsforce.min.js"></script>
  <script>
var sr = document.getElementById('sf-canvas-signed-request').content;
var conn = new jsforce.Connection({ signedRequest: sr });
conn.query('SELECT Id, Name FROM Account', function(err, res) {
  if (err) { return console.error(err); }
  console.log(res);
});
  </script>
</head>
<body>
</body>
</html>

Setup

$ npm install -g jsforce

Example


$ jsforce
> .connect username@salesforce.example.org
Password: *******
Logged in as : username@salesforce.example.org
> query("SELECT Id, Name FROM Account LIMIT 1")
{ totalSize: 1,
  done: true,
  records: 
   [ { attributes: [Object],
       Id: '0015000000KBQ5GAAX',
       Name: 'GenePoint' } ] }
> .exit

$ jsforce -c username@salesforce.example.org -e "query('SELECT Id, Name FROM Account LIMIT 2')"
{"totalSize":2,"done":true,"records":[{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001i0000009PyDrAAK"},"Id":"001i0000009PyDrAAK","Name":"GenePoint"},{"attributes":{"type":"Account","url":"/services/data/v29.0/sobjects/Account/001i0000009PyDsAAK"},"Id":"001i0000009PyDsAAK","Name":"United Oil & Gas, UK"}]}