function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rupali PophaliyaRupali Pophaliya 

How to fetch standard report data using apex?

Hi,

We want to fetch standard report data in apex so we are using following approach but we are just getting 1st column of standard report data.
How can we get all standard report data in apex?

Our approach:

Step -1
<Salesforce instance>/servlet/servlet.ReportList
From above link we are getting list of all reports with their report id and url.

Step - 2
sample response:

<result>
<report foldername="My Personal Custom Reports" name="Contact-Account Report">
<id><ID></id>
<url>
<![CDATA[ <ID>?isExcel=1 ]]>
</url>
<isPublic>false</isPublic>
</report>
<report foldername="Administrative Reports" name="All Active Users">
<url>
<![CDATA[
/00O?rt=32&retURL=%2Fservlet%2Fservlet.ReportList&t=active&c=FN&c=LN&c=RO&c=PR&c=UN&c=LL&duel0=FN%2CLN%2CRO%2CPR%2CUN%2CLL&details=yes
]]>
</url>
<description>Who are the active salesforce.com users?</description>
</report>
</result>
From above response we are just fetching "All Active Users" report url i.e
/00O?rt=32&retURL=%2Fservlet%2Fservlet.ReportList&t=active&c=FN&c=LN&c=RO&c=PR&c=UN&c=LL&duel0=FN%2CLN%2CRO%2CPR%2CUN%2CLL&details=yes
This url we are appending with &export=1&enc=UTF-8&xf=csv, by using this we can download file in csv form.

step -3
We are using following code to fetch standard report("All Active Users") data.
PageReference page = new PageReference('/00O?rt=32&retURL=%2Fservlet%2Fservlet.ReportList&t=active&c=FN&c=LN&c=RO&c=PR&c=UN&c=LL&duel0=FN%2CLN%2CRO%2CPR%2CUN%2CLL&details=yes&export=1&enc=UTF-8&xf=csv'); 
system.debug('response data=='+page.getContent().toString());
When we are executing above code then in response we are just getting 1st column data.
You can see column names in above url whose parameter name is "&c". In above case 1st parameter column name is &c=FN so I am just getting "FN" data.

If we are trying above url directly in browser then we are getting csv file with all data but in pageReference we are just getting 1st column data.
If we are removing all column parameter i.e "&c" param then in pageReference code we are getting all data for all columns but We don't want that because we want selected column data.

Instead of pageReference we have also tried with Http callout but there we are getting authentication failure.
We have also added session Id but facing with authentication failure.

How can we fetch standard report data in apex?

Thanks,
Rupali


Vamsi KrishnaVamsi Krishna
Hi,
you should be using the Analytics API to access the reports / dashboards and its data...

http://www.salesforce.com/us/developer/docs/api_analytics/index.htm
Rupali PophaliyaRupali Pophaliya
Thanks Vamsi. We want to fetch standard reports. The standard reports don't have IDs.
Steven Buelow 17Steven Buelow 17
Hey Rupali - I was just looking over some old answers and I saw nobody had responded to this last comment. Isn't the reason standard reports have no Id's because they themselves are live Rest calls via the analytics API?

Example, the standard reports aren't really saved in the traditional way (see they only have the save as button). You could easily save as and I see that new report has a ID in my dev box.

If you resolved this I'd be interested what you learned?