employer cover photo
employer logo
employer logo

Kcloud Technologies

Is this your company?

Kcloud Technologies interview question

Create a component using LWC which includes Apex code.

Interview Answer

Anonymous

15 Nov 2024

Create an Apex class to handle server-side logic #ApexCode public with sharing class AccountController { @AuraEnabled(cacheable=true) public static List getAccounts() { return [SELECT Id, Name, Industry FROM Account LIMIT 10]; } } #HTMLCode #HTML (accountList.html) <ul> <li> {account.Name} - {account.Industry} </li> </ul> <p>Error: {accounts.error}</p> #JavaScriptCode #JavaScript (accountList.js) import { LightningElement, wire, track } from 'lwc'; import getAccounts from '@salesforce/apex/AccountController.getAccounts'; export default class AccountList extends LightningElement { @wire(getAccounts) accounts; // Using @wire to call Apex method @track isLoading = true; connectedCallback() { this.isLoading = false; } } #CSSCode #CSS (accountList.css) /* Optional CSS for styling */ ul { list-style-type: none; padding: 0; } li { padding: 5px 0; border-bottom: 1px solid #ddd; } #Apex class (AccountController) #LWC files (accountList.html, accountList.js, and accountList.css)