1

We are novice to VisualForce Page and Apex development. Trying to create a new VF page using sandbox org. Also in that, we need to use jquery ajax callout.

We are trying to implement SFDC Analytics API : Salesforce-analytics-api-demo-code

Any help on it would be much appreciated

5

This tutorial from Pat Patterson (aka MetaDaddy, ex-Salesforce Developer Evangelist - Boy, do we miss him :() is a good starting point for how you can use Salesforce Analytics API on a VF page.

The key is to is to first fetch the reportId as shown below

// When the DOM is ready...
$(document).ready(function() {
    // Pass in the report ID like so:
    // https://c.prerelna1.visual.pre.force.com/apex/AnalyticsDemo?reportId=00Ox0000000fX7XEAU
    var reportId = '{!$CurrentPage.parameters.reportId}';

Initialise ForceTK (this is a wrapper for doing CRUD operations on Salesforce) as follows

if (reportId) {
    // Get an instance of the REST API client and set the session ID
    var client = new forcetk.Client();
    client.setSessionToken('{!$Api.Session_ID}');

    // We'll keep the report data around for the life of the page
    var report = null;

The report variable will hold your report data. Then call the Analytics API endpoint

client.ajax("/v29.0/analytics/reports/"+reportId+"?includeDetails=true", function(response){

This will give you the data returned from the Analytics API. You can then render it on VF page like any other data and in any format e.g. table view/ chart etc.. Refer to the provided link for more details.

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.