How to apply navigationmixin.navigate for navigate to different page like create new account record, web external url, visualforce page, contact list view, new tab and reports page uses of Navigation Service Library (NavigationMixin) in Lightning Web Component — LWC | apply navigationmixin for navitate to different page types like Navigate to Pages, Records, Lists, Visualforce, Tabs, Reports & web external url in LWC

6,741 views

Hey guys, today in this post we are going to learn about How to apply navigationmixin.navigate for navigate to different page like create new account record, web external url, visualforce page, contact list view, new tab and reports page uses of Navigation Service Library (NavigationMixin) in Lightning Web Component (LWC).

The lightning/navigation service is supported only in Lightning Experience, Experience Builder sites, and the Salesforce mobile app. It isn’t supported in other containers, such as Lightning Components for Visualforce, or Lightning Out. This is true even if you access these containers inside Lightning Experience or the Salesforce mobile app. To know more details about lightning/navigation service, Click Here.

 

Files we used in this post example →

lwcNavigateAction.html LWc HTML File Template HTML file to create Navitate to different page types in Salesforce Lightning Web Component (LWC)
lwcNavigateAction.js LWC JavaScript File It’s hold a javascript on click function to Navitate page on click button in lwc.
lwcNavigateAction.js-meta.xml XML Meta File It is used to where this lightning web component file you want to display as lightning__AppPage, lightning__RecordPage, lightning__HomePage.

 

Final Output →

navitate to different page types -- w3web.net

 

You can download file directly from github by Click Here.

 
 

Other related post that would you like to learn in Salesforce

  • Find the below steps

Create Lightning Web Component HTML

Step 1:- Create Lightning Web Component : lwcNavigateAction.html

SFDX:Lightning Web Component >> New >> lwcNavigateAction.html

lwcNavigateAction.html [Lightning Web Component HTML]

  1.    <template>
  2. <lightning-card>
  3.  
  4. <div class="slds-m-around_medium">
  5.     <h3 class="slds-text-heading_medium"><lightning-icon icon-name="custom:custom83" size="small"></lightning-icon> <strong style="color:#270086; font-size:13px; margin-right:5px;"> How to apply Navigation Service Library (NavigationMixin) in Lightning Web Component (LWC) </strong></h3>
  6.     <br/><br/>
  7.     <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_col-bordered" width="100%" border="1" bordercolor="#999" cellpadding="5" cellspacing="0" style="border-collapse:collapse; font-weight:bold;">
  8.         <tbody> 
  9.  
  10.         <tr>
  11.             <td valign="top" width="50%" style="background:#eee;"><lightning-button variant="brand" label="New Account" onclick={actionToCreateAccountNav}></lightning-button></td>
  12.             <td valign="top" width="50%" class="navigateTxt" >Navigate to Create New Account </td>        
  13.         </tr>
  14.  
  15.         <tr>
  16.             <td valign="top"  style="background:#eee;"><lightning-button variant="brand" label="Account Recent list View" onclick={actionToAccountListViewNav}></lightning-button></td>
  17.             <td valign="top"  style="color:#ff8000;">Navigate to Account List View </td>        
  18.         </tr>    
  19.         <tr>
  20.             <td valign="top"  style="background:#eee;"><lightning-button variant="brand" label="Navigate to Contact Recent View"  onclick={actionToContactHomeNav}></lightning-button></td>
  21.             <td valign="top"  style="color:#ff8000;">Navigate to Contact Recent View Page</td>        
  22.         </tr>
  23.  
  24.         <tr>
  25.             <td valign="top" style="background:#eee;"> <lightning-button variant="brand" label="Navigate to Files"  onclick={actionToFilesHomeNav}></lightning-button></td>
  26.             <td valign="top" style="color:#ff8000;">Navigate to Files</td>        
  27.         </tr>
  28.         <tr>
  29.             <td valign="top"  style="background:#eee;"><lightning-button variant="brand" label="Navigate to Home" onclick={actionToHomeNav}></lightning-button></td>
  30.             <td valign="top" style="color:#ff8000;">Navigate Home Page</td>        
  31.         </tr>
  32.         <tr>
  33.             <td valign="top"  style="background:#eee;"><lightning-button variant="brand" label="Navigate to Chatter Page" onclick={actionToChatterNav}></lightning-button></td>
  34.             <td valign="top"  style="color:#ff8000;">Navigate to Chatter Page</td>        
  35.         </tr>
  36.  
  37.         <tr>
  38.             <td valign="top"  style="background:#eee;"> <lightning-button variant="brand" label="Navigate to Reports" onclick={actionToReportsNav}></lightning-button></td>
  39.             <td valign="top"  style="color:#ff8000;">Navigate to Reports</td>        
  40.         </tr>
  41.  
  42.         <tr>
  43.             <td valign="top" style="background:#eee;"><lightning-button variant="brand" label="Navigate to Web Browser" onclick={actionToWebNav}></lightning-button></td>
  44.             <td valign="top" style="color:#ff8000;">Navigate to Web Browser</td>        
  45.         </tr>
  46.  
  47.         <tr>
  48.             <td valign="top" style="background:#eee;"> <lightning-button variant="brand" label="Navigate to Visualforce page " onclick={actionToVFNav}></lightning-button></td>
  49.             <td valign="top" style="color:#ff8000;">Navigate to Visualforce page</td>        
  50.         </tr>
  51.  
  52.  
  53.     </tbody>
  54.     </table>
  55.     <br/><br/>
  56.     <br/>
  57.    <!--Start RelatedTopics Section-->
  58. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  59.  
  60.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/05/thumbsUpLike.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="https://www.w3web.net/" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click  <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
  61.  
  62.             <br/><br/>
  63.             <p data-aura-rendered-by="435:0"><img src="https://www.w3web.net/wp-content/uploads/2021/07/tickMarkIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like →</span> </strong></p>
  64.             <div style="display:block; overflow:hidden;"> 
  65.                 <div style="width: 50%; float:left; display:inline-block">
  66.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  67.                         <li><a href="https://www.w3web.net/lwc-get-set-lightning-checkbox-value/" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
  68.                         <li><a href="https://www.w3web.net/display-account-related-contacts-in-lwc/" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
  69.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
  70.                         <li><a href="https://www.w3web.net/if-and-else-condition-in-lwc/" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
  71.                         <li><a href="https://www.w3web.net/get-selected-radio-button-value-and-checked-default-in-lwc/" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
  72.                     </ul>
  73.             </div>
  74.  
  75.             <div style="width: 50%; float:left; display:inline-block">
  76.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  77.                         <li><a href="https://www.w3web.net/display-account-related-contacts-lwc/" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
  78.                         <li><a href="https://www.w3web.net/create-lightning-datatable-row-actions-in-lwc/" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
  79.                         <li><a href="https://www.w3web.net/fetch-picklist-values-dynamic-in-lwc/" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
  80.                         <li><a href="https://www.w3web.net/edit-save-and-remove-rows-dynamically-in-lightning-component/" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
  81.                         <li><a href="https://www.w3web.net/update-parent-object-from-child/" target="_blank" rel="noopener noreferrer">update parent field from child using apex trigger</a></li>
  82.                     </ul>
  83.                 </div>
  84.                <div style="clear:both;"></div> 
  85.                <br/>
  86.                 <div class="youtubeIcon">
  87.                     <a href="https://www.youtube.com/channel/UCW62gTen2zniILj9xE6LmOg" target="_blank" rel="noopener noreferrer"><img src="https://www.w3web.net/wp-content/uploads/2021/11/youtubeIcon.png" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
  88.                 </div>
  89.     </div>
  90.  
  91. </div>
  92.  
  93.   <!--End RelatedTopics Section-->
  94. </div>
  95.  
  96. </lightning-card>
  97. </template>

Create Lightning Web Component JavaScript

Step 2:- Create Lightning Web Component : lwcNavigateAction.js

SFDX:Lightning Web Component >> New >> lwcNavigateAction.js

lwcNavigateAction.js [LWC JavaScript File]

  1.    import { LightningElement,api } from 'lwc';
  2. import { NavigationMixin } from 'lightning/navigation';
  3. export default class LwcNavigateAction extends NavigationMixin(LightningElement) {
  4.     @api recordId;
  5.  
  6.  
  7.  
  8.  
  9.     actionToCreateAccountNav() {
  10.         this[NavigationMixin.Navigate]({
  11.             type: 'standard__objectPage',
  12.             attributes: {
  13.                 objectApiName: 'Account',
  14.                 actionName: 'new'
  15.             },
  16.         });
  17.     }
  18.  
  19.  
  20.     actionToAccountListViewNav() {
  21.         this[NavigationMixin.Navigate]({
  22.             type: 'standard__objectPage',
  23.             attributes: {
  24.                 objectApiName: 'Account',
  25.                 actionName: 'list'
  26.             },
  27.             state: {
  28.                 filterName: 'Recent'
  29.             },
  30.         });
  31.     }
  32.  
  33.  
  34.     actionToContactHomeNav() {
  35.         this[NavigationMixin.Navigate]({
  36.             "type": "standard__objectPage",
  37.             "attributes": {
  38.                 "objectApiName": "Contact",
  39.                 "actionName": "home"
  40.             }
  41.         });
  42.     }
  43.  
  44.  
  45.     actionToFilesHomeNav() {
  46.         this[NavigationMixin.Navigate]({
  47.             type: 'standard__objectPage',
  48.             attributes: {
  49.                 objectApiName: 'ContentDocument',
  50.                 actionName: 'home'
  51.             },
  52.         });
  53.     }
  54.  
  55.  
  56.     actionToHomeNav() {
  57.         this[NavigationMixin.Navigate]({
  58.             type: 'standard__namedPage',
  59.             attributes: {
  60.                 pageName: 'home'
  61.             },
  62.         });
  63.     }
  64.  
  65.  
  66.     actionToChatterNav() {
  67.         this[NavigationMixin.Navigate]({
  68.             type: 'standard__namedPage',
  69.             attributes: {
  70.                 pageName: 'chatter'
  71.             },
  72.         });
  73.     }
  74.  
  75.  
  76.  
  77.     actionToReportsNav() {
  78.         this[NavigationMixin.Navigate]({
  79.             type: 'standard__objectPage',
  80.             attributes: {
  81.                 objectApiName: 'Report',
  82.                 actionName: 'home'
  83.             },
  84.         });
  85.     }
  86.  
  87.  
  88.     actionToWebNav() {
  89.         this[NavigationMixin.Navigate]({
  90.             "type": "standard__webPage",
  91.             "attributes": {
  92.                 "url": "https://www.w3web.net/"
  93.             }
  94.         });
  95.     }
  96.  
  97.  
  98.     actionToVFNav() {
  99.         this[NavigationMixin.GenerateUrl]({
  100.             type: 'standard__webPage',
  101.             attributes: {
  102.                 url: '/apex/wrapperRelatedListVfp?id=' + this.recordId
  103.             }
  104.         }).then(generatedUrl => {
  105.             window.open(generatedUrl);
  106.         });
  107.     }
  108.  
  109.  
  110. }

Create Lightning Web Component Meta XML

Step 3:- Create Lightning Web Component : lwcNavigateAction.js-meta.xml

SFDX:Lightning Web Component >> New >> lwcNavigateAction.js-meta.xml

lwcNavigateAction.js-meta.xml [LWC Meta Data XML]

  1.   <?xml version="1.0" encoding="UTF-8"?>
  2. <LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
  3.     <apiVersion>45.0</apiVersion>
  4.     <isExposed>true</isExposed>
  5.     <targets> 
  6.         <target>lightning__AppPage</target>
  7.         <target>lightning__RecordPage</target>
  8.         <target>lightning__HomePage</target>
  9.     </targets>
  10. </LightningComponentBundle>

Further post that would you like to learn in Salesforce

 

 


 

FAQ (Frequently Asked Questions)

How do I transfer record ID to LWC?

To get the current record ID in LWC, we just need to import the api decorator from lwc module. Then, we have to declare the property recordId with @api decorator.

What is connectedCallback in LWC?

The connectedCallback() is a lifecycle hook in lightning web component . It fires when a component is inserted into the DOM. It runs once when the component inserted.

What is disconnected callback in LWC?

The disconnectedCallback() lifecycle hook fires when a component is removed from the DOM. Both hooks flow from parent to child. You can't access child elements from the callbacks because they don't exist yet.

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

 
 


Hi, This is Vijay Kumar behind the admin and founder of w3web.net. I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on w3web.net

Leave a Comment