You need to sign in to do that
Don't have an account?
jaishri
In this below code account,contact and opportunity files on account page using lwc are displayed but files are not getting opened
<template>
<lightning-card title="File" icon-name="standard : Files">
<div class="slds‐m‐around_small">
<template if:true={filesList}>
<table class="slds-table slds-table_bordered slds-table_cell-buffer">
<thead>
<tr class="slds-text-title_caps">
<th scope="col">
<div title="Key">File Name</div>
</th>
<th scope="col">
<div title="Value">File Extension</div>
</th>
</tr>
</thead>
<tbody>
<template for:each={filesList} for:item="keyValue">
<tr key={keyValue.Id}>
<th scope="col">
<div>{keyValue.Title}</div>
</th>
<th scope="col">
<div>{keyValue.FileExtension}</div>
</th>
</tr>
</template>
</tbody>
</table>
</template>
</div>
</lightning-card>
</template>
import { LightningElement,api,wire } from 'lwc';
import queryFiles from '@salesforce/apex/filePreviewAndDownloadController.queryFiles'
export default class FileList extends LightningElement {
@api recordId;
wiredActivities;
filesList =[];
@wire(queryFiles, {recId: '$recordId'})
wiredclass(value){
this.wiredActivities = value;
const { data, error } = value;
if (data) {
console.log(data)
this.filesList = data;
console.log('Data========> '+JSON.stringify(this.filesList));
}
if(error){
console.log(error);
}
}
}
public with sharing class filePreviewAndDownloadController {
@AuraEnabled(cacheable = true)
public Static List<ContentVersion> queryFiles(String recId){
set<Id> SetIds = new Set<id>();
list<Account> lstAccount = [Select Id,(Select Id From Contacts),(Select Id From Opportunities) from Account where Id = :recId];
for(Account Acc : lstAccount){
SetIds.add(Acc.Id);
for(Contact con : Acc.Contacts){
SetIds.add(con.Id);
}
for(Opportunity opp : Acc.Opportunities){
SetIds.add(opp.Id);
}
}
List<ContentDocumentLink> files = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :SetIds];
List<ID> fileIDs = new List<ID>();
for (ContentDocumentLink docLink : files) {
fileIDs.add(docLink.ContentDocumentId);
}
List<ContentVersion> docs = [SELECT Id,ContentDocumentId, FileExtension, Title
FROM ContentVersion WHERE ContentDocumentId IN :fileIDs];
return docs;
}
}
<lightning-card title="File" icon-name="standard : Files">
<div class="slds‐m‐around_small">
<template if:true={filesList}>
<table class="slds-table slds-table_bordered slds-table_cell-buffer">
<thead>
<tr class="slds-text-title_caps">
<th scope="col">
<div title="Key">File Name</div>
</th>
<th scope="col">
<div title="Value">File Extension</div>
</th>
</tr>
</thead>
<tbody>
<template for:each={filesList} for:item="keyValue">
<tr key={keyValue.Id}>
<th scope="col">
<div>{keyValue.Title}</div>
</th>
<th scope="col">
<div>{keyValue.FileExtension}</div>
</th>
</tr>
</template>
</tbody>
</table>
</template>
</div>
</lightning-card>
</template>
import { LightningElement,api,wire } from 'lwc';
import queryFiles from '@salesforce/apex/filePreviewAndDownloadController.queryFiles'
export default class FileList extends LightningElement {
@api recordId;
wiredActivities;
filesList =[];
@wire(queryFiles, {recId: '$recordId'})
wiredclass(value){
this.wiredActivities = value;
const { data, error } = value;
if (data) {
console.log(data)
this.filesList = data;
console.log('Data========> '+JSON.stringify(this.filesList));
}
if(error){
console.log(error);
}
}
}
public with sharing class filePreviewAndDownloadController {
@AuraEnabled(cacheable = true)
public Static List<ContentVersion> queryFiles(String recId){
set<Id> SetIds = new Set<id>();
list<Account> lstAccount = [Select Id,(Select Id From Contacts),(Select Id From Opportunities) from Account where Id = :recId];
for(Account Acc : lstAccount){
SetIds.add(Acc.Id);
for(Contact con : Acc.Contacts){
SetIds.add(con.Id);
}
for(Opportunity opp : Acc.Opportunities){
SetIds.add(opp.Id);
}
}
List<ContentDocumentLink> files = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :SetIds];
List<ID> fileIDs = new List<ID>();
for (ContentDocumentLink docLink : files) {
fileIDs.add(docLink.ContentDocumentId);
}
List<ContentVersion> docs = [SELECT Id,ContentDocumentId, FileExtension, Title
FROM ContentVersion WHERE ContentDocumentId IN :fileIDs];
return docs;
}
}
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!