Inspecting Analytics API Object Details

I’ve been tinkering a fair amount with the Analytics API in Apex in a Spring ’14 pre-release org (see previous articles: here, here, and here).  One of the things that was helpful to me during development was being able to inspect information about the make up of a Report (e.g., metadata, extended metadata, report type metadata, etc.) or its data (e.g., report results) while developing.  It was helpful in debugging and also helpful in learning the API.

For example, it can be helpful to get a snapshot view of the entire contents of an instance of an Reports.ReportResult object.  It contains the results in the factMap, the Reports.ReportMetadata, the Reports.ReportExtendedMetadata, and the groupings of Reports.Dimensions as well as all of those objects children, and so on.   I found that simply outputting the variable value in a System.debug statement didn’t do the trick because the large amount of data wasn’t easily readable and it required the overhead of opening a debug log.  Also, setting a checkpoint in the Developer Console did not allow me to drill down to the level that was needed.

In the rest of this article, I describe some methods that I used to get at those details during development.

JSON Output

Apex contains a method for JSON pretty print serialization of objects, JSON.serializePretty(Object).  Using that, I was able to convert the complex object to a String and output it in the Visualforce page in a <pre> tag.  The value in this approach is that you can get a quick scan of the entire content of a complex object.  Here are simple snippets of controller and page code for that.

Development Mode Footer View State

The view state can be examined easily during development by turning on the Development Mode Footer and selecting to show the view state in development mode. It is harder to get an overall quick scan of everything, especially if there are many values, but it does provide a good way to drill in to individual values.

Development Mode footer exploring a Reports.ReportResult property

Using the Workbench

The Workbench REST Explorer can be used to issue REST-based analytics API requests. For example, to better understand the metdata about a specific report a GET request can be made to the describe resource, in the form of:
/services/data/<latest API version>/analytics/reports/<report ID>/describe.
The results can then be examined.  This approach is different in that the Apex code that you are developing isn’t actually executed, but instead the built in Analytics REST API is used directly to get the Report information.

Executing a GET for /services/data/v29.0/analytics/reports/00Oi0000004bu9t/describe resulted in the following:

Analytics REST request to describe resource

Using the REST-based Analytics API

If you are not developing with the Apex Analytics API, but are using the REST-based API instead, you can just use JavaScript to convert objects to JSON for debugging or just output to the browser console with console.log.  Pat Patterson has an example in his article Using the Salesforce Analytics API on a Visualforce Page.

One thought on “Inspecting Analytics API Object Details

Leave a Reply

Your email address will not be published. Required fields are marked *