Hey guys, today in this post we are going to learn about How to use Navigation Service (NavigationMixin.Navigate) to Visualforce Page in LWC.
Here are the steps to use the navigation service.
- Navigation service uses a PageReference.And a page reference is JavaScript that describes its page type, its attributes, and the state of the page.
- First, we need to import the lightning/navigation module.
- Use this Syntax:- Import {NavigationMixin} from ‘lightning/navigation;
Apply the NavigationMixin function to your component’s base Class.
Final Output →
Other related post that would you like to learn in Salesforce
Create HTML Page →
Step 1:- Create HTML Page : navigationPageLwc.html
navigationPageLwc.html [HTML PAGE]
<template>
<!-- Navigate to Visualforce Page-->
<lightning-card title="Navigate to Visualforce Page">
<div class="slds-m-around_medium">
<TABLE class="slds-table slds-table_bordered slds-table_col-bordered">
<tr>
<td STYLE="width:50%;">Navigation TO Visualforce</td>
<td STYLE="width:50%;">
<lightning-button variant="brand" label="Navigation to Visualforce Page" onclick={actionToNavigateVisualforce}></lightning-button>
</td>
</tr>
</table>
</div>
</lightning-card>
</template>
Create navigationPageLwc.js →
Step 2:- Create JavaScript Page : function.js
navigationPageLwc.js [JavaScript Page]
import { LightningElement, api } FROM 'lwc';
import {NavigationMixin} FROM 'lightning/navigation';
export DEFAULT class NavigationPageLwc extends NavigationMixin(LightningElement) {
//Navigate TO Visualforce
actionToNavigateVisualforce(){
this[NavigationMixin.Navigate]({
TYPE:'standard__webPage',
attributes:{
url:'/apex/pdfRenderVfp'
}
}).then(generatedUrl =>{
window.open(generatedUrl, "_blank")
});
}
}
Create Lightning Web Component Meta XML
Step 3:- Create Lightning Web Component : navigationPageLwc-meta.xml
SFDX:Lightning Web Component >> New >> navigationPageLwc-meta.xml
navigationPageLwc-meta.xml [LWC Meta Data XML]
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>59.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__RecordPage</target>
<target>lightning__HomePage</target>
</targets>
</LightningComponentBundle>
Further post that would you like to learn in Salesforce
How do I call a Visualforce page?
When using a Custom Action to call a Visualforce page from within the Quote Line Editor, use a relative URL so that custom actions can be migrated between orgs without issues with the different root URLs. On your Custom Action, set URL = /apex/c__MyPage, and the org will fill in the root URL automatically.
What is CurrentPageReference in lwc?
@wire(CurrentPageReference) captures the updated parameter state each time the page loads, then you can invoke your custom logic based on the new state parameter value. In this example, let us look at how to navigate to a LWC component embedded in a Lightning App Page using PageReference and eliminate the cache issue.
Inserting visualforce page in another VF page.
To insert VF page use include component and pagename attribute. This pagename attribute specifies the name of the visualforce page to be inserted.
Related Topics | You May Also Like
Our Free Courses →
👉 Get Free Course →
![]() 📌 Salesforce Administrators 📌 Salesforce Lightning Flow Builder 📌 Salesforce Record Trigger Flow Builder |
👉 Get Free Course →
![]() 📌 Aura Lightning Framework 📌 Lightning Web Component (LWC) 📌 Rest APIs Integration |