How can I access reports programmatically in SalesForce using Apex

I am trying to write an application on the SalesForce platform that can pull a list of contacts from a report and send them to a web service (say, send them by email or SMS).

The only way I can find this is to add the report results to the newly created campaign, and then access this campaign. It seems like a long way.

Every post I read on the web says that you cannot access reports through Apex, however, most or all of these posts were written before API version 20 was released last month in which a new report object was introduced . Now I can programmatically access the report information (for example, the last run, etc.), but I still cannot find a way to access the result data contained in this report.

Does anyone know if there is a way to do this?

+4
source share
5 answers

After much research on this, I found that the only way to do this at the moment is to clear the CSV document. I would suggest that Conga, etc. Use this particular method.

We have been doing this for a while, and it works. The only caveats:

  • Salesforce username / password / security token must be an application connection. If the password changes (and by default it is changed every 30 days or so), the token also changes and must be re-entered.

  • You need to know the account owner, which can be difficult to be right. For example, while most European accounts will use emea.salesforce.com to access CSV, our account uses na7 (North America 7), although we are located in Ireland. I am currently sending the page host to the application and parsing it to calculate the correct subdomain to use, but I think there should be a better way to do this.

Salesforce really needs to figure this out by providing an API call that allows us to export custom report results on the fly and allows us to use OAuth to connect to it. But, of course, this is unlikely to happen.

+7
source

In SalesforceSpring 11 update, it seems that you can get additional information about reports: As indicated in the API for Report and ReportType , you can get through Apex the fields used in the request in the report by reading the " columns " field, as well as the field used for views of filters called filters . "

Iterating through these objects should allow you to build a string that represents the same report request. After creating this line, you can make a dynamic query with a call to Database.query (..).

It seems like it's a little dirty, but should work .. (NOT TESTED!)

As header states, this only works with custom reports!

+2
source

But Conga (callxtremes) does this in its QuickMerge product, where the user specifies the identifier of the report, and the top of the script on the page launches the report to retrieve the results for the merge operation.

+1
source

Just to clarify for novice novices who find this when a question is asked, you can program access to your report data, but you had to use some hacking methods that are error prone.

All this is fixed, now you can access your reports through the API from the winter of '14.

Documentation here - http://www.salesforce.com/us/developer/docs/api_analytics/index.htm

Go to the city on these custom dashboards, etc. Crossroads published using Salesforce Stack Exchange - https://salesforce.stackexchange.com/questions/337/can-report-data-be-accessed-programatically/

+1
source

API v20.0 added metadata about reports, but could not actually run the report and get the results. If this is a standard report or a report that you have defined, you can generate an equivalent SOQL query for your report and run it, but if its report, defined by the end user, cannot do it.

0
source

All Articles