[SalesForce] Does support targeting Visualforce pages with URL parameters

I'm working on a Lightning component that includes a button, whose purpose is to load a Visualforce page rendering a PDF cover sheet. I'd like to use the most current supported functionality, so I'm using <lightning:navigation> to manage URL generation.

<lightning:navigation> is documented to support seven pageReference types, one of which is "Navigation Item Page".

This includes Visualforce pages which have custom tabs assigned to them – the tab's API name can be used as the target API name of the page reference. Using the Visualforce page's own API name does not work.

My controller does this:

    let pageReference = {
        type: 'standard__navItemPage',
        attributes: {
            apiName: 'Cover_Sheet'
        },
        state: {
            caseNumber: component.get('v.caseRecord.CaseNumber'),
            // ... other parameters ...
        }
    };

    component.find('navService').generateUrl(pageReference)
        .then($A.getCallback(function(url) {
            window.open(url);
        }), $A.getCallback(function(error) {
            helper.showToast('Unable to open cover sheet.', error);
        }));
},

The URL that's generated looks reasonable:

https://mysandbox.lightning.force.com/lightning/n/Cover_Sheet?caseNumber=03107407

although the /n/ format appears to be the new standard for targeting a named tab.

When I get into Visualforce, I do

System.debug(ApexPages.currentPage().getParameters());

and I don't find any of the parameters I wanted to set represented there:

11:36:56:051 USER_DEBUG [8]|DEBUG|{clc=1, isdtp=p1, ltn_app_id=06mC00000018GYXIA2, nonce=XXXXXXX, sfdc.tabName=01rW000000016SV, sfdcIFrameHost=web, sfdcIFrameOrigin=XXXXXX, tour=, vfRetURLInSFX=/home/home.jsp}

Being in a console or standard app doesn't make a difference.

Edit: Additionally, I tried prefixing the entries within the state key with c__, as with Lightning component attributes; this had no effect.

Is it possible to use <lightning:navigation> to target a Visualforce page while providing parameters in the URL, or are we stuck using other techniques to load the page?

Best Answer

Okay, there is a limitation in VF Tabs.

You cannot pass params in VF tabs let it be classic or even lightning.

On top of my head, it does not make sense to pass URL params to tabs. Tabs should be consistent irrespective of URL params.

As lightning:navigation use pageReference and pagereference does not support VF page, the option you have is to use standard__webPage provide your VF page with url params.

({
    handleClick : function(component, event, helper) {
        let pageReference = {
            type: 'standard__webPage',
            attributes: {
                url: '/apex/MyBlobVFPage?caseNumber=JAR'  
            },

        };
        var navService = component.find("navService");
        navService.generateUrl(pageReference)
            .then($A.getCallback(function(url) {
                console.log(url);
                navService.navigate(pageReference);


            }), $A.getCallback(function(error) {
                console.log(error); 
            }));
    }
})
Related Topic