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
Akhil Katkam 5Akhil Katkam 5 

how to get apex values to vs code using .then() function

Hi Developer Community,

I have a Query Regarding apex function call in LWC,

How can i get apex values to .then() function in LWC 

i have already imported apex class using import {}

now how can get values which are in apex class

please help me with the problem ,
Thanks in Advance
CharuDuttCharuDutt
Hii Akhil Katkam
Try Below Method
LWC
  <lightning-card title='Data-Table' icon-name="custom:custom11">
        &nbsp;&nbsp;&nbsp;&nbsp;{records} No. of Records Found
    <div style="height: 300px;">
        <lightning-datatable
                key-field="id"
                data={data}
                columns={columns}>
        </lightning-datatable>
        <div>{error}</div>
    </div>
</lightning-card>    


JS
import { LightningElement,wire } from 'lwc';
import getAccounts from '@salesforce/apex/dataTable.getAccounts';/*APEC Class Import*/
const columns = [
    { label: 'Label', fieldName: 'Name',editable : true },
    { label: 'Phone', fieldName: 'Phone', type: 'Phone',editable : true },
    { label: 'AnnualRevenue', fieldName: 'AnnualRevenue', type: 'Text' },
    { label: 'Industry', fieldName: 'Industry'},
    { label: 'Type', fieldName: 'Type', type: 'Picklist',editable : true },
];
export default class DataTable extends LightningElement {
    data = [];
    columns = columns;
    records = '';
    error;

/*Showing Imporeted APEX Class Data In Datatable*/
    @wire(getAccounts,{
        }
    )
    wiredCases(value){
        this.wiredActivities = value;
        const { data, error } = value;
    
    if(data){
        let dataEditing = JSON.parse(JSON.stringify(data));
        this.records = dataEditing.length;
        this.data = dataEditing;
        
    }else if(error){
        this.error = error;
    }
    
}
}




APEX
public with sharing class dataTable {
    public dataTable() {

    }
    @AuraEnabled(cacheable = true)
    public static List<Account> getAccounts(){
        List<Account> accList =[Select Name,Phone,AnnualRevenue,Industry,Type FROM Account];
        return accList;
    }
}
Please Mark It As Best Answer If It Helps
Thank You!