How to create tab for LWC in Salesforce

As part of your Salesforce development journey, you would have done custom development using LWC, Aura, VFPage etc. Once created these UI Components needs to be rendered in the screen for custom interaction, one such use-case can be to show LWC component in a tab. In today’s session we are going to walk through the process to create tab for LWC in Salesforce.

Watch the complete implementation below

Step by Step guide to show LWC in Custom Tab

This article covers:

Create an LWC Component and Expose it

Create an LWC Component and make the below code changes.

HTML Code

<template>
    <div style="background:white;height:500px">
        Welcome to my website {websiteName}
    </div>
</template>

This HTML is just a placeholder where we are showing a binding variable from the JS file.

JS Code

import { LightningElement } from 'lwc';

export default class CustomTab extends LightningElement {
    websiteName = 'SFDCRocks247'
}

This is a minimalistic code were are creating a variable and assign it a value.

Meta.xml Code

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>55.0</apiVersion>
    <isExposed>false</isExposed>
    <targets>
        <target>lightning__Tab</target>
    </targets>
</LightningComponentBundle>

The above configuration in meta.xml is the most important one, this is what enables this LWC to be available as an option when creating a custom tab.

Create a Lightning Component Tab

Create New Lightning Component Tab from Salesforce Setup.

From your Salesforce setup, search for Tabs and select the Tabs option under the User Interface option.

Select tabs from Salesforce Setup
Search tabs in Salesforce Setup

After opening the Custom Tabs scroll down to the Lightning Component Tabs section and click on the New button.

Create tab for LWC in Salesforce by using Lightning Component tab
Lightning Component Tabs in Salesforce

In the New Lightning Component Tab section, search for your LWC Component. You should be able to see and select your component.

Selecting component for which we want to create tab for LWC in Salesforce
Selecting LWC Component in the New Lightning Component tab

Set the profile level visibility for the tab created, for our example we have given the visibility for each profile.

Setting profile visibility for the Lighting Component tab
Setting profile visibility for the Lighting Component tab

Add custom tab to Salesforce App

Add the new tab to the Salesforce App.

After successfully creating the New Lightning Component Tab, we should add it to an Application.

In Salesforce setup search for app and select App Manager.

Search app in Salesforce setup
Search app in Salesforce setup

Select an app where we want to add this newly created Tab, and click on edit option(extreme right down arrow icon)

List of Apps in Salesforce
List of Apps in Salesforce

In the App Settings, click on Navigation Items and search for the Custom Lightning Tab created and move it to the right hand, selected items, side.

Selecting the custom tab for the Navigation of the App
Selecting the custom tab for the Navigation of the App

You should now be able to see your custom lightning tab with your LWC Component in the App.

Learning How to create tab for LWC in Salesforce
Showing custom LWC in Lighting Component Tab

Conclusion

Showing an LWC Component in a Custom Tab is one of the basic use cases that developers come across in their projects. In this article we have create a custom LWC component and a lightning tab then have included it in the Salesforce App.

Do follow these steps to create tab for LWC in Salesforce and see live changes on the customization you do on the component.

Do let us know your thoughts in the comment box below and share this article with your friends. Make sure to subscribe to our blog and get notified of new content being created.

One Comment