Im attempting to get the recordid from my lighting web component into my apex controller for sorting. Writing a component to display related tasks on the lighting page layout.
Would someone mind helping me with this?
Thanks
Apex Controller
public with sharing class dataTableLWC {
@AuraEnabled(cacheable = true)
public static List<Task> fetchTasks(String taskId){
return [SELECT Id,Subject,ActivityDate FROM TASK WHERE whatid = :taskId];
}
}
LWC - JS
import {
LightningElement,
wire,
track,
api
} from 'lwc';
//import method from the Apex Class
import fetchTasks from '@salesforce/apex/dataTableLWC.fetchTasks';
// Declaring the columns in the datatable
const columns = [{
label: 'View',
type: 'button-icon',
initialWidth: 75,
typeAttributes: {
iconName: 'action:preview',
title: 'Preview',
variant: 'border-filled',
alternativeText: 'View'
}
},
{
label: 'Subject',
fieldName: 'Subject'
},
{
label: 'Due Date',
fieldName: 'ActivityDate'
}
];
// declare class to expose the component
export default class DataTableComponent extends LightningElement {
@track columns = columns;
@track record = {};
@track rowOffset = 0;
@track data = {};
@track bShowModal = false;
@wire(fetchTasks) parameters;
@api recordId;
// Row Action event to show the details of the record
handleRowAction(event) {
const row = event.detail.row;
this.record = row;
this.bShowModal = true; // display modal window
}
// to close modal window set 'bShowModal' tarck value as false
closeModal() {
this.bShowModal = false;
}
}
LWC - HTML
<!-- Detail view modal start -->
<template if:true={bShowModal}>
<section role="dialog" tabindex="-1"
aria-labelledby="modal-heading-01"
aria-modal="true"
aria-describedby="modal-content-id-1"
class="slds-modal slds-fade-in-open">
<div class="slds-modal__container">
<!-- modal header start -->
<header class="slds-modal__header">
<button class="slds-button slds-button_icon slds-modal__close slds-button_icon-inverse" title="Close" onclick={closeModal}>
<lightning-icon icon-name="utility:close" alternative-text="close" variant="inverse" size="small" ></lightning-icon>
</button>
<h2 id="modal-heading-01" class="slds-text-heading_medium slds-hyphenate">Record Detail</h2>
</header>
<!-- modal body start -->
<div class="slds-modal__content slds-p-around_medium" id="modal-content-id-1">
<dl class="slds-list_horizontal slds-wrap">
<dt class="slds-item_label slds-truncate" title="Subject">Subject:</dt>
<dd class="slds-item_detail slds-truncate">{record.Subject}</dd>
<dt class="slds-item_label slds-truncate" title="DueDate">Due Date:</dt>
<dd class="slds-item_detail slds-truncate">{record.ActivityDate}</dd>
</dl>
</div>
<!-- modal footer start-->
<footer class="slds-modal__footer">
<lightning-button variant="brand"
label="Close"
title="Close"
onclick={closeModal}
></lightning-button>
</footer>
</div>
</section>
<div class="slds-backdrop slds-backdrop_open"></div>
</template>
<!-- Detail view modal end -->
</template>