How to navigate to report from Lightning Web Component(LWC) in Salesforce?

How to navigate to report from Lightning Web Component(LWC) in Salesforce?

NavigationMixin.Navigate with type as ‘standard__recordPage’ can be used to navigate to report from Lightning Web Component(LWC) in Salesforce.

Sample Code:

HTML:

<template>
    <lightning-card>
        <lightning-button
            label="View Report"
            onclick={viewReport}></lightning-button>
    </lightning-card>
</template>

JavaScript:

import { LightningElement } from 'lwc';
import { NavigationMixin } from 'lightning/navigation';

export default class ReportNavigation extends NavigationMixin( LightningElement ) {

    viewReport( event ) {
        
        this[ NavigationMixin.Navigate ]({
            type: 'standard__recordPage',
            attributes: {
                recordId: '00O8c000007uh5UEAQ',
                objectApiName: 'Report',
                actionName: 'view'
            }
        });

    }

}

JS-meta.xml:

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

Output:

Leave a Reply