+ Start a Discussion
Rupali PophaliyaRupali Pophaliya 

How to fetch standard report data using apex?


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:

<report foldername="My Personal Custom Reports" name="Contact-Account Report">
<![CDATA[ <ID>?isExcel=1 ]]>
<report foldername="Administrative Reports" name="All Active Users">
<description>Who are the active salesforce.com users?</description>
From above response we are just fetching "All Active Users" report url i.e
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?


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

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?