Friday, September 2, 2011

Few "Salesforce Reports" tips and tricks

Again, it's been long time since my last post. But, better late than never. Isn't it? :)

Lets discuss about some tips and tricks for salesforce reports.

1. First of all, if we want to access a list of all the  reports programatically, you can get it in xml format by opening following URL:
"https://instance.salesforce.com/servlet/servlet.ReportList". Needless to say, you have to be logged into your salesforce instance.

2. Next, let us say we want to show a particular report in a visualforce page on a link/button click. Simply include an iFrame in the page with src="https://instance.salesforce.com/00Ox000000xxxxx".
This was simple one. Right? :)

3. But, the above page will have one problem, it will show the headers in the iFrame which looks kind of odd to have two headers (list of tabs visible).
So, how to remove this. Simple, just modify the URL by putting "?isdtp=mn" in the end. Which makes the URL look like this:
"https://instance.salesforce.com/00Ox000000xxxxx?isdtp=mn". And whooshh. The header is gone.

4. Now, let us assume you need to give a direct download link to a report in csv/xls format. The url for the link would be:
"https://instance.salesforce.com/00Ox0000000xxxx?export=1&enc=UTF-8&xf=csv" or "https://instance.salesforce.com/00Ox0000000xxxx?export=1&enc=UTF-8&xf=xls".
This is done by setting the parameters export, enc (encoding) and xf (the format). One thing is quite interesting here, the "xls" format report is not "a native excel file".
They just format it in this way and put an ".xls" extension, so that by default it opens with MS Excel. However, if you try to open this file in some mobile application which supports excel files, it wont open properly as it is not actually an excel file.

5. Finally, this one will look an old one, but still useful.
Suppose we want to give some filter criteria for a report at run time (e.g. there is report link visible to all but the filter criteria for country depends on user's country).
For this, create a report; create the filter but don't but any values in the filter. Keep them empty.Now, build a URL in the following format:
"https://instance.salesforce.com/00Ox0000000xxxx?pv0=India&pv1=Active" (assuming filter 1 is for country and 2 is for some status field).
The values "India" and "Active" can be dynamically generated in a controller class.
If you have more filters, you can continue to pv2, pv3 and so on.

There are some more parameters that you pass in the URL to do a thing or two. For example to delete a report the URL would be something like this:
"https://instance.salesforce.com/00Ox0000000xxxx?delrep". Want to explore more thing? Open a report, view HTML source and find out the actions of the buttons/links on the report page.


Don't forget to put Id of your report instead of the ones given in the examples :).


Please note that the salesforce may change any of the above parameters without notice (may be not so soon though) bacause they don't provide standard API access to these thing and not even standard documentation.


These tricks are for in situations when you are asked "just do it" and you have no standard documented way of doing it.

There are very little documentation for point 5. You can find one of them here.

You can find some more references from "Salesforce Heretic blog (http://sfdc-heretic.warped-minds.com/2006/04/10/progmatic-access-to-salesforcecom-reports/)" and developer force discussion boards.

Let me know if any of the above tricks don't work for you.



Cheers. Happy Clouding :)