I am trying to display results from the apex on to the data table,the subqeury should return only 1 record for each parent record. able to display the fields from the parent object but the child records from the subquery is returned as a collection so what kind of manipulation of data do I need to do here to get this working.
Apex
public with sharing class Controller {
@AuraEnabled
public static List<ContentDocument> getContentDocument(Id recordId){
try {
return [SELECT Title, (Select ContentUrl from ContentVersions where IsLatest=true),(Select LinkedEntityId from ContentDocumentLinks where LinkedEntityId=:caseId) FROM ContentDocument ];
} catch (Exception e) {
throw new AuraHandledException(e.getMessage());
}
}
}
JS
import { LightningElement,api,wire } from 'lwc';
import getContentDocument from '@salesforce/apex/Controller.getContentDocument';
const columns = [
{ label: 'File Name', fieldName: 'Title', type: 'text' },
{ label: 'File Type', fieldName: 'FileType', type: 'text' },
{ label: 'URL', fieldName: 'ContentUrl', type: 'URL' }
];
export default class DocumentCenter extends LightningElement {
@api recordId;
documents;
columns = columns;
@wire(getContentDocument, { $recordId: '$recordId' })
getContentDocument({ error, data }) {
if (data) {
this.documents = data;
} else if (error) {
}
}
HTML
<template>
<lightning-card>
<template if:true={documents}>
<lightning-datatable
key-field="Id"
data={documents}
columns={columns}
>
</lightning-datatable>
</template>
</lightning-card>
</template>