function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Mike Tol 1Mike Tol 1 

Data of Lead doesn’t redirect to the detail page current Lead

Hi!
I have lead table.
User-added image

I need that when I click on the name of the lead, it opens the detail page current Lead.
The link seems to work, but the detail page current Lead does not open. Please tell me how to fix it.

My code:
Html:
<template>
    <lightning-card title="Leads">
        <lightning-layout multiple-rows="true" vertical-align="end">
           
            <lightning-layout-item size="12" padding="around-small">
                <lightning-datatable key-field="id" data={leads} columns={columns}></lightning-datatable>
            </lightning-layout-item>
           
        </lightning-layout>
    </lightning-card>
</template>

Js:
import { LightningElement , wire} from 'lwc';
import getLeads from '@salesforce/apex/Qqq.getLeads';
const columns = [
    { label: 'Name', fieldName: 'Name', type: 'url',
    typeAttributes: {label: {fieldName: "Name"}, tooltip: "Name", linkify: true} },
    { label: 'Title', fieldName: 'Title', type: 'text' },
    { label: 'Phone', fieldName: 'Phone', type: 'text' }    
];
export default class LightningDatatableLWCExample extends LightningElement {
    columns = columns;
    leads;
   
    @wire(getLeads)
    wiredLeads(value) {
        const {error, data} = value;
        if (data) {
            let leadData = JSON.parse(JSON.stringify(data));  
            leadData.forEach(record => {
                            if (record.LeadId) {
                                record.recordLink = "/" + record.LeadId;  
                                record.LeadName = record.Lead.Name;
                            }
                        });  
            this.leads = leadData;
        } else if (error) {
            this.error = error;
        }
    }
}
 
Best Answer chosen by Mike Tol 1
ravi soniravi soni
hi Mike,
here is my code. you can get some refrence from my code.
<template>
    <lightning-card title="Leads">
        <lightning-layout multiple-rows="true" vertical-align="end">
           
            <lightning-layout-item size="12" padding="around-small">
                <lightning-datatable key-field="id" data={leads} columns={columns}></lightning-datatable>
            </lightning-layout-item>
           
        </lightning-layout>
    </lightning-card>
</template>
==================================================================
import { LightningElement , wire} from 'lwc';
//import getLeads from '@salesforce/apex/Qqq.getLeads';
import getLeads from '@salesforce/apex/fetchLead.getLeads';



const columns = [
    { label: 'Name', fieldName: 'recordLink', type: 'url',
    typeAttributes: {label: {fieldName: "LeadName"}, tooltip: "Name", linkify: true} },
    { label: 'Title', fieldName: 'Title', type: 'text' },
    { label: 'Phone', fieldName: 'Phone', type: 'text' }    
];
export default class LeadTable extends LightningElement {
    columns = columns;
    leads;
   
    @wire(getLeads)
    wiredLeads(value) {
        const {error, data} = value;
        if (data) {
            let leadData = JSON.parse(JSON.stringify(data));  
            leadData.forEach(record => {
                            //if (record.Id) {
                                record.recordLink = "/" + record.Id;  
                                record.LeadName = record.Name;
                            //}
                        });  
            this.leads = leadData;
        } else if (error) {
            this.error = error;
        }
    }
}
=====================================================
public class fetchLead {
@AuraEnabled(cacheable=true)
public static list<lead> getLeads(){
return [SELECT Id,Name,Title,Phone FROM Lead limit 5];
}
}

don't forget to mark it as best answer.
thank you

All Answers

ravi soniravi soni
hi Mike,
here is my code. you can get some refrence from my code.
<template>
    <lightning-card title="Leads">
        <lightning-layout multiple-rows="true" vertical-align="end">
           
            <lightning-layout-item size="12" padding="around-small">
                <lightning-datatable key-field="id" data={leads} columns={columns}></lightning-datatable>
            </lightning-layout-item>
           
        </lightning-layout>
    </lightning-card>
</template>
==================================================================
import { LightningElement , wire} from 'lwc';
//import getLeads from '@salesforce/apex/Qqq.getLeads';
import getLeads from '@salesforce/apex/fetchLead.getLeads';



const columns = [
    { label: 'Name', fieldName: 'recordLink', type: 'url',
    typeAttributes: {label: {fieldName: "LeadName"}, tooltip: "Name", linkify: true} },
    { label: 'Title', fieldName: 'Title', type: 'text' },
    { label: 'Phone', fieldName: 'Phone', type: 'text' }    
];
export default class LeadTable extends LightningElement {
    columns = columns;
    leads;
   
    @wire(getLeads)
    wiredLeads(value) {
        const {error, data} = value;
        if (data) {
            let leadData = JSON.parse(JSON.stringify(data));  
            leadData.forEach(record => {
                            //if (record.Id) {
                                record.recordLink = "/" + record.Id;  
                                record.LeadName = record.Name;
                            //}
                        });  
            this.leads = leadData;
        } else if (error) {
            this.error = error;
        }
    }
}
=====================================================
public class fetchLead {
@AuraEnabled(cacheable=true)
public static list<lead> getLeads(){
return [SELECT Id,Name,Title,Phone FROM Lead limit 5];
}
}

don't forget to mark it as best answer.
thank you
This was selected as the best answer
Mike Tol 1Mike Tol 1
Hi ravi! 
Thanks a lot!