Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Salesforce by (11.9k points)

I am trying to retrieve the results of a Salesforce Report programmatically.

Often referenced is this blog about scraping the results from the web site, but the method is unsupported: http://sfdc-heretic.warped-minds.com/2006/04/10/progmatic-access-to-salesforcecom-reports/.

I can get a list of reports via the REST API:

require 'restforce'

restforce_client = Restforce.new(

    :refresh_token => <refresh token>,

    :client_id => <client id>,

    :client_secret => <client secret>

)

reports = restforce.query("SELECT Id,DeveloperName FROM Report")

reports.last.DeveloperName

 => "Rob_Test_Report"

I've also tried retrieving via the Metadata SOAP API ReportFolder object:

require 'metaforce'
metaforce = Metaforce.new(
    :username => <username>,
    :password => <password>,
    :security_token => <security token>
)
report_folders = metaforce.list_metadata('ReportFolder')
report_folders.last.full_name
 => "RobTestReportFolder"

I can see the folder. I haven't retrieved the contents yet but even when I do it seems that I would just be getting the metadata around the report itself (i.e. the filter criteria), not the results of the report. The metadata API is discussed here: https://success.salesforce.com/questiondetail?qId=a1X30000000IQ8pEAG. Is this correct?

I saw this similar question from a couple of years ago but did not know if it was correct or anything had changed in the API: How do I access reports programmatically in SalesForce using Apex

Is it possible to export or pull the results of a Report through a supported Salesforce API?

1 Answer

0 votes
by (32.1k points)
edited by

You can't retrieve the results of a report without you use the Analytics API. If you want to participate in the pilot, let me know and I will submit your request.

Once in the Pilot, you use a REST endpoint passing in the Id of the report. You will have two endpoints-- a describereport endpoint and a runreport enndpoint. What is returned from describeReport is a JSON representation of the metadata for the report (describes the dimensions and facts and such) and from runReport a JSON representation of the data.

Once you have the data you can do with it what you will. The report data is only available at the summary level and for the pilot only summary and matrix reports are supported.

Go for this in-depth job-oriented salesforce training online now!

Related questions

Browse Categories

...