0

I am trying to display Account list view just like we see in Salesforce standard list view so I am trying to use lightning ui* adaptor I have used this module - lightning/uiListsApi and adaptor config is - getListInfoByName Please check my code

import { LightningElement, wire } from 'lwc';
import { getListInfoByName } from 'lightning/uiListsApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';

export default class GetListAPI extends LightningElement {
  listViewData;
  @wire(getListInfoByName, { objectApiName: ACCOUNT_OBJECT.objectApiName, listViewApiName: 'AllAccounts' })
    listViewWire({ error, data }) {
        if (data) {
            console.log('data inside list view',data);
            this.listViewData = data.displayColumns;
            this.error = undefined;
        } else if (error) {
            this.data = undefined;
            console.log('data inside list view',error);
            console.error(error);
        }
    }
}

<template>
    <lightning-card title="wireListInfoByName">
      <template lwc:if={listViewData}>
        <div class="slds-m-around_medium">
          <template for:each={listViewData} for:item="col">
            <p key={col.fieldApiName}>{col.fieldApiName} : {col.label}</p>
          </template>
        </div>
      </template>
    </lightning-card>
  </template>

Here I can see only list view field name but I want to see all records in a lightning datatable

I know this is not the correct way , as it only display fields/column name I need to display Account list view complete with all account records in the form of list

Please suggest me what I should do

Thanks

0

1 Answer 1

0

Try fetching the Account data through an Apex Controller like this:

public with sharing class AccountController {
    @AuraEnabled(cacheable=true)
    public static List<Account> getAccounts() {
        return [SELECT Id, Name FROM Account LIMIT 200];
    }
}

then your js would like something like this:

import { LightningElement, wire } from 'lwc';
import getAccounts from '@salesforce/apex/AccountController.getAccounts';
import { getListInfoByName } from 'lightning/uiListsApi';
import ACCOUNT_OBJECT from '@salesforce/schema/Account';

export default class GetListAPI extends LightningElement {
    listViewData;
    accountData;
    columns = [ 
        { label: 'Account Name', fieldName: 'Name', type: 'text' }
    ];

    @wire(getListInfoByName, { objectApiName: ACCOUNT_OBJECT.objectApiName, listViewApiName: 'AllAccounts' })
    listViewWire({ error, data }) {
        if (data) {
            console.log('data inside list view',data);
            this.listViewData = data.displayColumns;
            this.error = undefined;
        } else if (error) {
            this.data = undefined;
            console.log('data inside list view',error);
            console.error(error);
        }
    }

    @wire(getAccounts)
    accountDataWire({ error, data }) {
        if (data) {
            console.log('Account data', data);
            this.accountData = data;
            this.error = undefined;
        } else if (error) {
            this.accountData = undefined;
            console.error(error);
        }
    }
}

html:

<template>
    <lightning-card title="wireListInfoByName">
        <template if:true={listViewData}>
            <div class="slds-m-around_medium">
                <template for:each={listViewData} for:item="col">
                    <p key={col.fieldApiName}>{col.fieldApiName} : {col.label}</p>
                </template>
            </div>
        </template>
        <template if:true={accountData}>
            <lightning-datatable
                key-field="Id"
                data={accountData}
                columns={columns}
                hide-checkbox-column="true">
            </lightning-datatable>
        </template>
    </lightning-card>
</template>

1
  • thank you for reply, but I dont want to use Apex class, is there any way to use lightning *ui adaptor only to show list view of Object Commented Oct 1, 2023 at 17:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .