No need to futz with filters! Pass URL parameters to set filter values in Lightning Experience reports. When linking to reports or when bookmarking a report, add filter value parameters to the URL to customize how the report filters when opened. For example, bookmark your opportunities report and add a filter value parameter to specify whether you see New Business or Existing Business. This feature is new in Lightning Experience.
Periodically throughout your day you check your opportunities report, and after opening it, you always edit a filter to show New Business or Existing Business. (The Type filter includes both New Business and Existing Business by default.)
Instead of loading the report, editing the filter, and reloading the report, create two bookmarks. One with a filter value parameter for New Business, and one with a filter value parameter for Existing Business. Take note of the opportunities report URL.
Edit the URL to set the Type filter value to New Business by appending the parameter &fv0=New%20Business. The full, bookmarked URL reads:
Below is the description of the parameters defined:
- & — Denotes a new parameter in the URL. If no other parameters are present in the URL, then substitute ? in place of &.
- fv0 — The fv stands for “filter value,” and is the name of the parameter. The 0 is the numerical order in which the filter appears in the report. (The first filter is 0, the second filter is 1, the third is 2, and so forth.) Standard filters don’t count in this order, and can’t be filtered using URL parameters, although they appear as the first three filters on any report. To set the value of the fifth filter in the report, specify fv4. In our example, we’re filtering the first field filter in the report, the Type filter.
The order in which filters appear in Lightning Experience on the report run page isn’t necessarily the order that filters appear in the report. Locked filters are listed beneath unlocked filters on the run page, but aren’t necessarily ordered after all the unlocked filters. To see the order of filters in your report, refer to their order in the Report Builder. Alternatively, make a GET call to /services/data/v39.0/analytics/reports/<report ID>/describe and note their order in the JSON response.
- =New%20Business — Specifies that the Type filter value is New Business.
The parameter value must be URI encoded, which means certain characters (such as spaces) must be written in a format that URLs can understand. In our example, the space (‘ ‘) between “New” and “Business” becomes %20 when URI encoded.
When you navigate to your opportunity report through the URL with a filter value parameter, the report opens filtered and ready to read.
But, Setting filter values via the URL, also have some Limitations, which are defined below:
- Only field filters support edits from URL parameters. Standard filters (role hierarchy filters, scope filters, date filters), cross filters, and row limit filters aren’t supported. Standard, cross, and row limit filters don’t count when listing filters — fv0 is the first field filter.
- Chart filters aren’t supported.
- Filter operators (like equals and greater than) can’t be modified via URL parameters.
- You can’t change the field being filtered via URL parameters.
- You can’t add new filters to reports using filter value URL parameters. You can only modify existing filters.
- You can’t delete filters from reports using filter value URL parameters. Setting a blank value filters by no text or numerals, but doesn’t remove the filter.
It is important to remember that dynamic reports can contain more than one criteria element.
The flexibility built into the Salesforce platform allows developers to generate a report using criteria found on different Objects without writing a single line of code. Instead, you can leverage the URL used to open that report along with some little-known features within the reporting framework.
The process of generating the Dynamic Report requires three steps to complete:
- Determine which object will launch the report.
- Create the dynamic report.
- Add the formula field to the object.
This is about how we can create dynamic reports in Classic View in Salesforce:
Suppose if we want to show two reports with filter “Account Name equals abc” and “Account Name equals xyz”. So, there is no need to create two different reports for it, we can pass filter value in URL at runtime.
Now create two link which will redirect to a VFP, with the filter parameter value by which report will be filtered. Now this VFP will redirect to report URL, e.g. https://……/<reportId>?pv0=paramValue.
Value passed in pv0 will automatically become the filter value for the report. Now if I pass ?pv0=abc report will show me all account with name “abc” and if I pass ?pv0=xyz report will show me all account with name “xyz”.
Like this if we have more than one filters then we can also pass values for them like pv0 , pv1 , pv2 and so on.
References: Salesforce Spring ’17 Release Notes