0

I've seen many questions on accessing Visualforce pages from LWC, including the following Is it possible to navigate to a Visualforce page from an LWC with parameters and community compatible however to date I've still been unable to get this to work. What I am trying to do is replicate the following URLFOR in a Lignting Web Component

{!URLFOR(IF($Site.prefix == '/s','/apex/dfsle__gendocumentgenerator', $Site.Prefix +'/apex/dfsle__gendocumentgenerator'), null, [sId = Opportunity.Id, templateId = 'a201q000001vutgAAA', recordId = Opportunity.Id, title = 'Generate Doc'])}

I tried var urlVal = '/apex/dfsle__gendocumentgenerator'; this[NavigationMixin.GenerateUrl]({ type: 'standard__webPage', attributes: { url: urlVal, sId: this.recordId, templateId: this.value, recordId: this.recordId, title: 'GenerateDocument' } }).then(generatedUrl => { window.open(generatedUrl); });

I tried var urlVal = '/s/apex/dfsle__gendocumentgenerator?sId=' + this.recordId + '&templateId=' + this.value + '&recordId=' + this.recordId + '&title='Generate Document'';

this[NavigationMixin.Navigate]({
            type: 'standard__webPage',
            attributes: {
                         url: urlVal
                        }
            }, 
            false); 

I tried this[NavigationMixin.GenerateUrl]({ type: 'standard__webPage', attributes: { url: urlVal } }).then(generatedUrl => { window.open(generatedUrl); });

For each of these I get "The link you followed isn’t valid. This page requires a CSRF confirmation token. Report this error to your Salesforce administrator."

Is it correct that using "NavigationMixin" means this should not occur?

Could it be an issue with it being a managed package VF page?

Can I directly implement a URLFOR in LWC? I note in the answer in the linked question that an Apex PageReference has been returned to help the process? Would NavigationMixin not eleviate the need for such a requirement?

Thanks in advance for any further pointers on this.

0
0

Same solution using an Apex function as per Is it possible to navigate to a Visualforce page from an LWC with parameters and community compatible applied. I had wondered if it could have been done without Apex but I was unable to do so.

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.