Way number one call apex method from javascript file
1. Simple way to communicate with apex controller:
wireMethod.cmp :
wireMethod.cmp :
<template>
<lightning-card title="Case Details" icon-name="standard:case">
<div class="slds-m-around_small">
<template for:each={cases.data} for:item="item">
<p key={item.Id}>
Name: {item.Subject}<br/>
Description: {item.Description}<br/>
Status: {item.Status}<br/>
Origin: {item.Origin}<br/>
Priority: {item.Priority}<br/>
-------------------------
</p>
</template>
<template if:true={cases.error}>
There is a error while fetching the error.
</template>
</div>
</lightning-card>
</template>
wireMethod.js:
import { LightningElement, wire, api } from 'lwc';
import getAllCase from '@salesforce/apex/CaseController.getAllCase';
export default class WireMethod extends LightningElement {
@wire(getAllCase) cases;
}
CaseController.apex :
public with sharing class CaseController {
public CaseController() {
}
@AuraEnabled(cacheable=true)
public static List<Case> getAllCase(){
return [
Select Subject,Description,Status,Origin,Priority from Case
];
}
}
No comments