2

I need to go to a Visualforce page from a Lightning Component. The page has CSRF protection enabled.

I'm trying to use navigateToURL action but it causes the "The link you followed isn’t valid. This page requires a CSRF confirmation token. Report this error to your Salesforce administrator." error.

    const navigateEvent = $A.get("e.force:navigateToURL");
    navigateEvent.setParams({
        "url" : "/apex/TestVisualforceCSRFPage"
    });
    navigateEvent.fire();

How can I direct a user to the Page bypassing the error?

0

Ok, I've found the answer. It's not very beautiful though.

The only way to go from a lightning component to a visualforce page is to use Apex Controller and

Aura.redirect(PageReference pageRef)

method.

Please note, that the Aura.redirect() cannot be covered with unit tests due to "Internal Salesforce.com error" issue. To avoid that I have to use !Test.isRunningTest() workaround.

Hope this will be helpful for someone.

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.