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. I am passionate about Salesforce, and I enjoy the friendly ecosystem that is filled with talented, intelligent professionals.
Posts created 50

17 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.

  2. Thanks for this update as it helped me piece together some snippets and get to the final result, had 8 reports done and 1 failure so still investigating that one. I used workbench to find the column that and report ID to Firefox which shows the un-encoded version then copy and pasted it to chrome which auto encodes it following on to create the buttons etc.
    Maybe thinking it can only handle as certain length of column name or levels deep.

  3. This is great! Like finding a needle in a haystack for this particular problem. You should cross-post this to the various Success and Developer questions on this topic.

  4. I am haveing some issues where a report type has a 2 level deep lookup to a Record ID to filter on but I cant seem to get it working. Is there a limitiation on this.

  5. This worked well for us! One snag is that the linked filter it creates is removable. Any way to lock it down so the users can’t just remove the filter and see more data?

  6. Thanks! This was very helpful! In case it helps anyone else, my final formula looked like this, so it could work in both the lightning portal and community. In the end I had to copy my report since I needed the filter for the lightning portal and couldn’t have the filter for the community:
    {!IF( $Site.Prefix=null,
    URLFOR(‘/lightning/r/report/00O0V000005ZBntUAG/view?fv0=’+Course__c.Id),
    URLFOR($Site.Prefix+’/s/report/00O7j000000SgMTEA0/view?reportFilters=%5B%7B%22operator%22%3A%22equals%22%2C%22value%22%3A%22’+Course__c.Id+’%22%2C%22column%22%3A%22Course__c.Id%22%7D%5D’)
    )}

  7. A total lifesaver! Thanks, Chris. There isn’t a whole lot of material for communities and this is a true gem.

  8. Hey Chris!
    Thanks for this! Would you mind helping me out with this issue? I have applied the report filters as described in the article. The generated url too shows the correct values still the filter value does not apply. When I checked in the filter panel it showed a different value for the same column.

    Url: https://clientcommunity.force.com/clientname/s/report/00O1Q000007rr7EUAQ/object-change-log?reportFilters=%5B%7Boperator%3Aequals%2Cvalue%3Ahigh%2Ccolumn%3A%7BColumnname%7D%7D%5D

    Filter applied is ‘Columnname equals high’ whereas in reality in the panel it shows ‘Columnname equals low’. I am clueless here what could be the issue.

    1. I would double-check the column’s name. Columnname doesn’t look like the typical value applied by Salesforce in a report. I tried following the link, but don’t have a login to look myself.

  9. Hi Chris,

    Appreciate the help here a lot. I definitely would not have solved this without finding the solution here. I’m not able to figure this out just yet, but are we able to pass more than one filter field into the report?

    1. Yes, you can pass additional filters as long as you keep the JSON format intact. The format for two filters would look something like this:
      [{“operator”:”equals”,”value”:”0011b000000000″,”column”:”Id”},{“operator”:”equals”,”value”:”Other”,”column”:”CUSTOM_FIELD”}]

      (That’s not URL encoded, but much easier to read.)

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