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..!

No comments: