0

I have a Visualforce page that contains a link to a custom report. I'm generating that link in an apex class like this:

reportUrl = '/'  + reportId

Then in the VF page I create the link and add the filter:

<apex:outputLink value="{!reportURL}" target="_blank">
    Open Report
    <apex:param name="fv1" value="{!URLENCODE(userName)}"/>
</apex:outputLink>

This worked well SF Classic where the parameter name in the VF code had to be "pv1". In Lightning that has changed to "fv1". Now when I generate the URL it looks just like the classic version but with the "fv1" as expected. However, when I click on the URL in Lightning it redirects and I end up with a different URL that takes me to the report but doesn't include the filter parameter.

Generated URL: https://my_domain.my.salesforce.com/00O40000003SdKeEAK?fv1=Bob%20Smith

Redirected URL: https://my_domain.lightning.force.com/lightning/r/Report/00O40000003SdKeEAK/view

If I take the redirected URL and manually add the "?fv1=Bob%20Smith" then the filter shows up so I know the Lightning report works with the filter parameter.

Is there a way to get the Lightning version of the URL from the Apex class so I can append the filter parameters to that?

0

https://help.salesforce.com/articleView?id=reports_filter_url.htm&type=0

The document goes through the format and filter format for URLs in Lightning.

In your apex, append the needed parts.

reporturl = '/lightning/r/Report/ + reportId + '/view?fv0' + ' whatever + '&fv1=' + ....
1
  • Thanks for your suggestion. That link is where I figured out that the parameter name changed in Lightning. It doesn't tell you how to the the URL though. I can do as you suggested. It just seems like, if they have a mechanism to get the URL, it should provide the correct one based on the version of SF you're currently in. I don't see the need for the redirect. – JeffMc Oct 4 '19 at 19:20
0

You can handle the report link with filter parameter by detecting the user theme i.e. classic or lightning in your apex class and then generate the URL according to the theme as follow:-

String theme = UserInfo.getUiThemeDisplayed();
if(theme=='Theme3'){
reportUrl = '/'  + reportId + 'pv1='+username;
}else if(theme=='Theme4d' || theme =='Theme4t'){
reportUrl = '/lightning/r/Report/' + reportId + '/view?fv1='+username;
}

Note:- pv0 will work in Classic only and fv0 will work in Lightning only. Also, When the user right-clicks and opens the URL in a new tab, the filter will not be applied in lightning because theme detection will result in the classic theme value.

Read more here about theme detection:- Introducing UI Theme Detection for Lightning Experience

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.