Today, I stumbled across an interesting problem, where one needs to
“Run a report by passing parameters through link or button click”
Their is no direct way visible in report configuration screen for the same. So I scanned salesforce developer boards for the same, and found this solution that worked perfectly for me, thanks “mikef” for sharing this solution(can’t find your twitter profile ). Using the same example in discussion board, we will see next how you create a sample Account report and pass its filters as query params. These steps mentioned by “mikef” will be followed next in the post:
First step: Create your report. Make sure the report is saved somewhere other then your customer report folder.
Second step: Add all the filters you need, ie if you want to pass in the State value create a fileter ShippingState equals and leave the value box blank.
Third step: Create your button to the report. use the id of the report. ie. /00O800000044Dq6?pv0={!ShippingState}
Now you see the /ID and then after that is a ‘?’ that starts your url query string. The ‘pv0’ is the first value box in the report filters, so if you want the second you say pv1 and so on.
First Step : Create an Account report !
I am assuming we all are too good in this, so skipping details of this I have completed this step and I am on report configuration page for Account sobject.
Second Step : Add filters !
On the Account report configuration view, I added filters on two fields i.e. “Type” and “Industry”, each with value equals blank(“”). Same is shown below :

Hit “Save”, followed by “Run report”. Obtain the report ID shown next after you save or run report, easiest way to do that is copy it from your browser’s address bar. In my case its something like “https://ap1.salesforce.com/00O90000001HwVr”, so my report id turns to be “00O90000001HwVr”
Third Step : Create a link/button for executing this report.
Here is the sample visualforce page code that creates the hyperlink and passes two params, each for “Type=Customer-Direct” and “Industry=Energy”.
<apex:page >
<a href="/00O90000001HwVr?pv0=Customer%20-%20Direct&pv1=Energy" > Run Accounts Report </a>
</apex:page>
One can also run this report by directly hitting following URL in browser, I used this practice to test several combinations as its much faster then creating pages and buttons.
https://ap1.salesforce.com/00O90000001HwVr?pv0=Customer%20-%20Direct&pv1=Energy
Either way, i.e. hyperlink or direct url. Results will be as follows

You might need to tweak and play with param “pv”, “pv0——–pvN” to get the correct index of filters in query params. One can easily do that by saving the report once and playing with params using the report id url shown above.
Needless to say, you can create hyperlink and buttons in many more smarter and dynamic ways, to pass user-provided inputs to run these reports in visualforce pages etc, (including that piece is out of scope for this post)
Important points to consider !
As said by mikef in the discussion board thread
Some negative issues are if a user changes your report the button might not work correctly, and there is no error checking for null values.
So if we are using this hack, one needs to be careful about changes/addition of new filters to the reports.
If you have other interesting ways to pass dynamic params to report, please share !
Comments (21)
Anonymoussays:
May 16, 2011 at 4:10 pmHi Abhinav,I am trying to add a link on a report, that will open the record, in a window. can this be done without doing a vf page?
Anonymoussays:
May 16, 2011 at 4:11 pmgr8 post…
Anonymoussays:
May 17, 2011 at 3:13 amThanks Kris, we just need to create a link like this > /00O90000001HwVr?pv0=Customer%20-%20Direct&pv1=Energyit doesn't needs to be in a VF page. If you want to write a formula that populates query params like pv0.. pvn that will be good per record too.
Anonymoussays:
August 3, 2011 at 11:55 amHi Abhinav,If i want to pass more than 255 characters through URL how can I do that??because at a time we cant pass more than 255 characters through any URLany Inputs on this???
Anonymoussays:
August 11, 2011 at 2:55 amno way Sunil, we can't bypass HTTP norms, even though its cloudy all around 🙂
Anonymoussays:
August 12, 2011 at 10:20 amIs there any other way to pass more than 255 characters to report other than URL??
Anonymoussays:
August 12, 2011 at 11:24 amNo, reports give limited flexibility in this regard.
Anonymoussays:
October 26, 2011 at 6:52 pmHelpful article…thanks!Can the same technique be used to pass values into a case listview? That is, I created a Case View with a single filter criteria(Subject Contains “”). Want to pass in a string so that resulting view filter is “Subject Contains “.Am trying something like what you did here for reports:https://na2.salesforce.com/500?fcf=3D00B40000006DVsz?pv0=TestStringBut doesn't seem to passing String into the filter. The view returned by the URL above is still using original filter criteria(ie Subject Contains “”).
Anonymoussays:
October 26, 2011 at 7:18 pmNot sure about list views @Unknown. A small change should fix it for reports i.e. you need to use “&” instead of “?” before pv0 param. Changed url shown below :https://na2.salesforce.com/500?fcf=3D00B40000006DVsz&pv0=TestString
Anonymoussays:
November 5, 2011 at 2:13 pmCan you pls post an example how to acheive this using custom setting objectThanks
Anonymoussays:
November 6, 2011 at 2:43 pmSure Amy, right now I am tight but will do that soon.
Anonymoussays:
December 13, 2011 at 12:13 pmHi, i have created a custom link on account detail page. the link works fine if there is no white space. this link works fine https://na11.salesforce.com/00OG0000002imXl?pv0=test+agency as it is an account “test agency” but it failed to pull the report when the account name is “test agency, LLC”. the link is display as https://na11.salesforce.com/00OG0000002imXl?pv0=test+agency%2C+LLC. when i look at the report it removes the space between comma and LLC. please help.
Anonymoussays:
December 13, 2011 at 12:25 pmBaskaran, can you please try using URL Encoding for ex. Javascript's encodeURI () function or something similar in Apex.Or try directly using the encoded value “test%20agency,%20LLC” for “”test agency, LLC”
Anonymoussays:
February 17, 2012 at 6:40 amHi,I am displaying reports in client portal and while displaying the report we see all the ugly filter parameters like all the account ids i had passed and all the years and months I was passing.Is there a way to add a parameter to my report string which would hide the filter parameters or any other way would do too.By the way I am using iframe for displaying the reports.Pranay
Anonymoussays:
February 17, 2012 at 7:56 amNot sure Pranay,I believe if you can encrypt all the params to one string and decrypt them using Javascript then it might help.For ex. the whole URL would be yourdomain.com?param=232r2hjk2h3jk2h3k23hk23hkjJavascript will decrypt it to individual yourdomain.com?pv0=1222Hope this helps.
Anonymoussays:
February 17, 2012 at 8:38 amHi Abhinav, What I meant was that when the report gets generated on the page we see all the passed parameters, and not the URL, something like this Filtered By: Account: Account ID equals 001Z0000002eOwY AND Service Type equals Natural Gas,Electricity – Retail AND Period greater or equal “201,201” AND Period less or equal “201,212”I looked at the source and this whole code is displayed in a div tag called filterHeader. I tried to make its visibility=none, but it did not work.
Anonymoussays:
March 15, 2012 at 6:32 amFantastic post. Here’s a tool that lets you build all types of online reporting with graphs and charts for sales, marketing, finance, HR, support, etc. http://blog.caspio.com/web_apps/how-to-add-dynamic-data-charts-and-graphs-to-your-web-apps/
Anonymoussays:
April 11, 2012 at 6:30 pmHow about trying to filter the report by User?I tried appending ?pv2={$User} but that does not seem to work. It thinks I am trying to filter the user column, in the report, by text “$User” instead of the User's actual name.
Anonymoussays:
April 12, 2012 at 2:15 am$User is a variable specific to visualforce pages and formula type fields, it will never work in requests. Try passing user id, it might help.
Anonymoussays:
June 14, 2012 at 11:00 amI have a custom link on campaigns; it's a URL which passes the Campaign ID in as pv0 to a Campaign Member report. Works fine. Now I want to use this report in the Service Cloud Console, opening it on a subtab when I open a campaign in the primary tab. This is done with Visualforce; the code uses the sforce.console.OpenSubtab method as explained at http://wiki.developerforce.com/page/Open_Multiple_Subtabs When deploy my page and open a campaign, the campaign-member report opens but with no results. The problem appears to be that the key part of the code (below) passes the 18-character Campaign ID, which causes the report to run but return no results. The pv0 report custom link passes the 15-character ID, which succeeds. How can I amend the code below to pass the 15-character ID? // Use the results primary tab id and open a new subtab var openSubtab = function(result) { sforce.console.openSubtab(result.id,'/00O60000002xNrr?pv0={!Campaign.Id}',false,'Campaign Member Report'); clearTimeout(openSubtabTimer); }; // Get the enclosing primary tab id. The openSubtab method is set as the callback sforce.console.getEnclosingPrimaryTabId(openSubtab); }
Anonymoussays:
June 14, 2012 at 5:34 pmTry using Javascript subString function to trim the last 3 chars off the 18 digit id ?