0

I am trying to get all records from a specific Report. I am using NodeJS and the library JSforce.

I have tried using the following code:

var report = conn.analytics.report(reportId);
report.execute({ details: true }...)

But I'm only able to fetch 2000 records(salesforce limitation)

2

This is a documented limitation of the Analytics API:

The API returns up to the first 2,000 report rows. You can narrow results using filters.

You could approach this by segmenting your data using narrower filters and running multiple reports to aggregate the total data set.

  • thanks for the quick reply @david-reed, I need to fetch all records in a specific Report, do you mean that I should split the report in chunks of max 2000 records? – Cristian-Florin Pandele Jun 3 '19 at 14:28
  • 1
    Yes, unless you can simply rewrite the report as a SOQL query. – David Reed Jun 3 '19 at 14:31
0

Below are some methods to get all records via soql, but not through analytics api.

Digging around in the docs for reporting execution shows that there are no values such as "autofetch" or "queryall" that could be used here.

You have a few options still:

  1. Ask the author on GitHub (maybe we missed something or theres some upcoming feature that could help)
  2. Translate your report metadata back into a query and execute the query using the below code.
  3. Just write a soql query & use that instead.

No matter what if you want over 2k records you'll need to run a soql query. Guessing the reporting page does some kind of translating as well to get the full 2k records.


This example shows how to query "all" records from a table without using the autofetch option provided by the developer.

describe("query big tables without autoFetch", function() {
    it("should scan records in one query fetch", function(done) {
      var records = [];
      var query = conn.query("SELECT Id, Name FROM " + (config.bigTable || 'Account'));
      query.on('record', function(record, i, cnt){
        records.push(record);
      });
      query.on('end', function() {
        callback(null, { query : query, records : records });
      });
      query.on('error', function(err) {
        callback(err);
      });
      query.run({ autoFetch : false });
      var callback = function(err, result) {
        if (err) { throw err; }
        assert.ok(result.query.totalFetched === result.records.length);
        assert.ok(result.query.totalSize > 2000 ?
                  result.query.totalFetched === 2000 :
                  result.query.totalFetched === result.query.totalSize
        );
      }.check(done);
    });
  });

This example shows how to use the autofetch option provided by the developer to obtain all rows from a table.

describe("query big tables with autoFetch", function() {
    it("should scan records up to maxFetch num", function(done) {
      var records = [];
      var query = conn.query("SELECT Id, Name FROM " + (config.bigTable || 'Account'));
      query.on('record', function(record) {
             records.push(record);
           })
           .on('error', function(err) {
             callback(err);
           })
           .on('end', function() {
             callback(null, { query : query, records : records });
           })
           .run({ autoFetch : true, maxFetch : 5000 });
      var callback = function(err, result) {
        if (err) { throw err; }
        assert.ok(result.query.totalFetched === result.records.length);
        assert.ok(result.query.totalSize > 5000 ?
                  result.query.totalFetched === 5000 :
                  result.query.totalFetched === result.query.totalSize
        );
      }.check(done);
    });
  });

Both examples are taken from the repo's test classes, found here.

  • That's for SOQL queries, though. Analytics API has a separate limitation analogous to the Reporting UI. – David Reed Jun 3 '19 at 14:09
  • In theory, using a callback on a query to keep calling the query until no results are found should still work - just like the "without autofetch" example. I'm pretty out of my depth however, I just figured any answer beats no answer. – battery.cord Jun 3 '19 at 14:11
  • thank you for your answer @battery.cord, but do you know how I can return all records in that specific report? instead of id and name? – Cristian-Florin Pandele Jun 3 '19 at 14:23
  • No, you'll need to run a query somehow. – battery.cord Jun 3 '19 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.