Wednesday, December 4, 2019

Hyperlinks in Lightning-DataTable To Open The Record Detail Page In Classic Console

In my previous post we have seen how to open record detail page directly from the lightning data table .If the same thing you wants to do it in Classic Console where your visual force is loading the LWC component then that will not work.

Please do the below changes to work the same in Classic console as well.The major change involves at Url param and target param in columns section.

Change the target attribute to '_top' and append the console#%2F in the redirection url

AccountListTable.js

import { LightningElement ,wire,track} from 'lwc';
import getAllOpps from '@salesforce/apex/GetAllAccountsCntrl.getAllAccounts';

export default class AccountListTable extends LightningElement {
    @track columns = [
        {
            label: 'Account Name',
            fieldName: 'nameUrl',
            type: 'url',
            typeAttributes: {label: { fieldName: 'Name'}, 
            target: '_top'},
            sortable: true
        },
        {
            label: 'Account Source',
            fieldName: 'AccountSource',
            type: 'text',
       
        },
  {
            label: 'Website',
            fieldName: 'Website',
            type: 'text',
        },
        {
            label: 'Close date',
            fieldName: 'closeDate',
            type: 'date',
        }

    ];

    @track error;
    @track listAccsData = [];


    @wire(getAllAccounts)
 wiredAllAccounts({ error, data }) {
        if (data) {
         
            this.listAccsData = data.map(record => Object.assign(
                { "nameUrl": '/console#%2F'+record.Id},
                record
            ));
        
        }
        else if (error) {
            this.error = error;
            this.listAccsData = null;
          
        }
 }
}


Hope this helps you..Enjoy..!

3 comments:

  1. Did not working this link in my code please help me

    My Code:
    -------
    {
    label: 'Subject',
    fieldName: 'nameUrl',
    type: 'url',
    typeAttributes: {label: { fieldName: 'Subject' },
    target: '_blank'},
    sortable: true
    },

    @wire(getactivities,{recordId: '$recordId'})
    openactivities(result) {
    this.refreshTable = result;
    if (result.data) {
    this.data = result.data;
    this.error = undefined;
    this.data = result.data.map(record => Object.assign(
    { "nameUrl": '/lightning/r/Task/'+record.Id},
    record
    ));
    } else if (result.error) {
    this.error = result.error;
    this.data = undefined;
    }

    }

    ReplyDelete
    Replies
    1. This peace of code is to open the hyperlink in the classic console not in the lightning console or lightning experience. If your trying in lightning please share the what is the error your getting in console logs on click of hyperlink.

      Delete
  2. How can i call lightning record page

    ReplyDelete