3

I am trying to write a simple node app to get the record count from various objects in salesforce.

Following rest api gives the count for objects mentioned in the request

/services/data/v45.0/limits/recordCount?sObjects=Account,User

I am not sure how to call this rest api from jsforce. Tried following the jsforce documentation but no luck so far.

appreciate your help!

1 Answer 1

7

I have figured this out. Posting answer hoping it would help others.

var jsforce = require('jsforce');
var conn = new jsforce.Connection({
  // you can change loginUrl to connect to sandbox or prerelease env.
  loginUrl : 'https://test.salesforce.com'
});

var _request = {
  url: '/services/data/v45.0/limits/recordCount?sObjects=Account,User',
  method: 'get',
  body: '',
  headers : {
          "Content-Type" : "application/json"
      }
};

conn.login('username', 'pwd', function(err, userInfo) {
  if (err) { return console.error(err); }
  // Now you can get the access token and instance URL information.
  // Save them to establish connection next time.
  console.log(conn.accessToken);
  console.log(conn.instanceUrl);
  // logged in user property
  console.log("User ID: " + userInfo.id);
  console.log("Org ID: " + userInfo.organizationId);

  // var records = [];
  // conn.query("SELECT Id, Name FROM Account", function(err, result) {
  //   if (err) { return console.error(err); }
  //   console.log("total : " + result.totalSize);
  //   console.log("fetched : " + result.records.length);
  // });

  conn.request(_request, function(err, resp) {
      console.log(resp);
  });


});

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .