Salesforce Report Parameters in a Community

Salesforce Report Parameters in a Community URL

Recently I was working with a colleague on an interesting client request. The client had a custom report built to show quote line data. Internally, they used the common URL parameter functionality provided by Salesforce. They created a custom button to pass in the Quote Id, which filtered the report results. This is simple to do by appending ?fv0={value} to the report’s URL, explained in the Salesforce documentation. But that same process doesn’t work to pass Salesforce report parameters in a community.

Community URL Parameter Limitations

In a Salesforce community, appending those same ?fv0={value} report parameters doesn’t yield any filtered results. Instead you get an error message. But the client uses a partner community and needed to expose this same functionality to their partners.

With a little digging (and trial and error), we discovered that you can pass parameters in, but you need to use a JSON format. That format looks like this:

?reportFilters=[{"operator":"equals","value":"0011b000000000","column":"Id"}]

Using that format, you are able to pass in an id, name, or other information, in order to filter the report.

Additionally, setting the filters in this manner extends the capabilities. You aren’t restricted to setting the value on an existing filter, you can create a net new filter!

Setting Salesforce Report Parameters in a Community

Now, in order to use this in your community, there are a few steps to get things working.

  1. You need to convert to a URL encoded format to use this in a button.
  2. You need to find the column name that will be used to filter your report (which may require a little digging)
  3. Add your community URL to the prefix, and insert your merge fields

I’ll walk through the setup I created in a developer org to protect client anonymity.

Salesforce community report URL parameters

Here is our button on the Quote object. We are creating a simple detail page button, which we’re opening in a new window.

Encoded URL

The URL encoded format of our report parameters looks like this:

/bolt/s/report/00O4p000003wTmvEAE?reportFilters=%5B%7B%22operator%22%3A%22equals%22%2C%22value%22%3A%22{!SBQQ__Quote__c.Id}%22%2C%22column%22%3A%22CUST_ID%22%7D%5D

Community URL

Breaking that down, the first portion is the URL to our specific report (/bolt/s/report/00O4p000003wTmvEAE). The 00O is our report id, and the /bolt/ is our specific community instance. To utilize this in your org, replace those two pieces.

Report Filters

Next we have our reportFilters= code, but with the URL encoding for the symbols. We have the different parameters we can set (operator, value, and column).

In our use case, we want to use the quote’s id to filter the report. So we have the operator set to equals, but we could have used other operators (like contains, greater than, etc.).

Our value is the quote id. Using the ‘Insert Merge Field’ capability of the button builder, you can insert any piece of information from your record.

Our column is the field that will filter the report based on our starting record. In our use case, we are using the quote id to find related quote lines. But as you can see, I didn’t pass in “Id”, it is set to “CUST_ID”. Why?

Depending on what object your report lives, you may have a custom or standard report type. Because of those differences, your column may have a unique name that needs to be called. Even though ‘Name’ and ‘Id’ are common across all Salesforce objects, those may not be available in your report.

Finding Your Column Name

When creating our button, we ran into this error:

For the filter 3: Specify a valid filterable column because Id is invalid.

This error was frustrating, because the Id column was on the report (although not required to accomplish this), we had a filter created for Id (also not required), but couldn’t get past this error.

If you run into this error as well, you need to find out what your column is actually called. In order to find that, we need to call the Analytics API. The steps for this process are as follows:

  1. Open the Developer console.
  2. Fro the drop down menu, choose ‘Debug > Open Execute Anonymous’ window.
  3. In the ‘Enter Apex Code’ window, paste the following, replacing your report id:
String reportId = '00O250000000000'; 

Http http = new Http();
       HttpRequest httpReq = new HttpRequest();
       HttpResponse httpRes = new HttpResponse();      
       httpReq.setMethod('GET');
       httpReq.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
       httpReq.setEndpoint(
           URL.getSalesforceBaseUrl().toExternalForm()+
           '/services/data/v29.0/analytics/reports/' + reportId +
           '?includeDetails=true'
       );
       httpRes = http.send(httpReq);
       System.debug(httpRes.getBody());
  1. Click the ‘Open Log’ checkbox and execute the code.
  2. On the log, right click and choose ‘Open Raw Log’.
Salesforce community report URL parameters
  1. Look for either reportFilters (for existing filters to use) or detailColumns (for columns in the report) and find the name of the field next to column.
Report Filters
Report Columns

In our case, we are after the quote’s id, so we used ‘CUST_ID’.

Conclusion

With our URL created, and button added to the partner page layout, clicking the button successfully opened a new window with the filtered report.

Salesforce report parameters a in community

If you attempt this in your org, let me know in the comments below.

I am a 24x Salesforce certified consultant, currently working for the implementation partner Simplus. I am passionate about Salesforce, and I enjoy the friendly ecosystem that is filled with talented, intelligent professionals.
Posts created 42

2 thoughts on “Salesforce Report Parameters in a Community URL

  1. Hi Chris,

    very helpful article, thank’s a lot. Exactly the same challenge here – I was nearly giving up, then your post brought me on the right track.

    By the way, for getting the right COLUMN value, I just downloaded the report definition in VSCode – seemed faster to me.

    Thank you!

    1. Glad you found it helpful. After hitting my head against the problem for hours, I figured someone else might get some value.

      As for VSCode, I actually also used that for the values. I wanted to give a non-developer option, but it is more cumbersome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top