The Problem:

Salesforce has made Einstein Analytics available to many more customers by including some level of Einstein Analytics based on the newest partner program. However, Salesforce doesn’t provide an easy way to calculate the org’s total or remaining Einstein Analytics dataset rows.

This creates a problem for ISVs. At some point, you’ll run out of rows and you won’t be able to proceed unless you make a purchase from Salesforce — and if you’re in the middle of a project with a tight timeline, delays like this can cause a project to stall out.

I’ve put together a solution that does two things:

  1. Helps you calculate your total dataset rows (depending on the various licenses you have, this number can widely vary)
  2. Determine how many rows you have remaining in your org

To simplify the process a bit, I’ve added the entirety of the code to a repo here: https://github.com/drewcoparker/sf-analytics-api-service/blob/master/AnalyticsAPIService.cls

Solution: An Apex Approach

While Salesforce does not provide a direct way to query your total Einstein Analytics dataset rows, you can still come about this number by using a combination of two techniques:

  1. Get the total amount of dataset rows you’ve used so far: Use Saleforce’s Analytics REST API to fetch all your datasets, loop through each, and sum their rows used.
  2. Get your org’s allotted amount of dataset rows: Perform a SOQL query for all the pertinent Einstein Analytics licenses your org has (there could be a variety) and run a tally of rows each may give you (this will require hard-coding values gleaned from documentation, more on that later).

Before you can interact with the Analytics REST API, you’ll first need to add your org’s base url to the allowed sites in Remote Site Settings, i.e., `https://app-flow-3189-dev-ed.lightning.force.com/`

Interact with the Analytics REST API

Salesforce provides excellent documentation for the Analytics REST API on the Developer Guide page. To access the API, you’ll need some apex code to initiate a GET request. Below is a method that demonstrates how to request data from the Analytics API.

Later, I’ll introduce another method that will use the one above to fetch Einstein Analytics datasets.

Analytics REST API: Fetch your org’s total dataset rows

You may have several Einstein Analytics projects within your org, each with zero or more associated datasets. Each of those datasets may be using zero or more rows. The Analytics API is your tool of choice for accessing your total rows, but there’s a small problem: you can’t fetch them in one call. Here’s how you’ll need to do it:

  1. First fetch all your org’s dataset Ids (each will have info on its row usage).
  2. Then fetch the total rows used for each dataset.

The method below demonstrates how to structure the first part of this multi-part fetch request, getting all of the dataset Ids.

Now, you can create a final method that will use the one above to loop through each dataset and make additional requests for their totalRows. Here’s an example of how to do precisely that:

The above two methods constitute the first part of this blog’s solution: getting the total amount of dataset rows you’ve used so far. Now, let’s examine how to compute your org’s total allotted amount.

Einstein Analytics Limits: Dataset Row Storage Allocations

Salesforce states that “Your org’s total row storage limit is a combination of your org’s active licenses.” We can create a method that uses SOQL to do just that. We’ll use the chart in the Dataset Row Storage Allocations section of Einstein Analytics documentation to describe the allocation rules programmatically.

It is important to note that these limits are set by Salesforce and will likely be adjusted in the future. To ensure this code works appropriately, please reference the documentation and make updates where necessary.

Let’s begin by determining which EA license level you’re using, Einstein Analytics Plus or Einstein Analytics Growth.

Einstein Analytics Plus gives you an allotment of 10 billion of dataset rows while Einstein Analytics Growth yields 100 million. Observe that we query the PermissionSetLicense sObject for licenses that contain the word “Einstein” in the label and initialize a variable to account for their allotment.

From there, we’ll need to further our query to find any related licences that can grant additional allotments towards the base 10 billion or 100 million. The documentation is very specific with how additional allotments are tallied. It states, “If your org has an Einstein Analytics Plus license and adds the Event Monitoring license, your total row limit becomes 10.05 billion. (10 billion plus 50 million).”

Let’s take a look at how that can be reflected as an addendum to our code above:

The full method representing the two snippets in this section can be found here. Once run, it will return to you precisely how many rows you can use in your org. While having this information on hand will be good enough for some ISVs, you can take this a step further and create components to showcase this information like in our mock up below.

To simplify accessibility, all code referenced in this post can be accessed in full on GitHub here.


Curious how your app can leverage Einstein Analytics? CodeScience enables businesses to do more on Salesforce than they thought possible. Our mission is to help every partner thrive on the AppExchange. Get in touch today!