Since we cannot modify the permissions or the out-of-the-box (OOTB) button, one potential solution is to create a custom component using an LWC datatable. You can try the solution below and further optimize the code based on your needs and best practices. Hope this helps!
Apex Controller
public with sharing class AccountFilesController {
@AuraEnabled(cacheable=true)
public static List<ContentDocument> getAccountFiles(String accountId) {
List<ContentDocumentLink> lstCDL= new List<ContentDocumentLink>();
Set<Id> cdlId = new Set<Id>();
lstCDL =[ SELECT ContentDocumentId
FROM ContentDocumentLink
WHERE LinkedEntityId = :accountId];
for(ContentDocumentLink objCDL:lstCDL){
cdlId.add(objCDL.ContentDocumentId);
}
// Query the files related to the Account
if(cdlId!=null){
List<ContentDocument> files = new List<ContentDocument>();
files = [
SELECT Id, Title, FileType, ContentSize, CreatedDate
FROM ContentDocument
WHERE Id IN :cdlId
];
return files;
}
return null;
}
}
LWC Component
HTML
<template>
<lightning-card title="Account Files">
<template if:true={files}>
<lightning-datatable
key-field="id"
data={files}
columns={columns}
hide-checkbox-column="true">
</lightning-datatable>
</template>
<template if:true={boolerror}>
Sorry, there is Error!
</template>
</lightning-card>
</template>
JS File
import { LightningElement, api, wire } from 'lwc';
import getAccountFiles from '@salesforce/apex/AccountFilesController.getAccountFiles';
const columns = [
{ label: 'Title', fieldName: 'Title', type: 'text' },
{ label: 'File Type', fieldName: 'FileType', type: 'text' },
{ label: 'Size (Bytes)', fieldName: 'ContentSize', type: 'number' },
{ label: 'Created Date', fieldName: 'CreatedDate', type: 'date' }
];
export default class filesLWCRelatedList extends LightningElement {
@api recordId;
columns = columns;
files;
boolerror;
connectedCallback(){
this.getfilesmethod();
}
getfilesmethod(){
getAccountFiles({accountId: this.recordId})
.then(result => {
if(result && result != null ){
this.files = result.map(file => ({
Id: file.Id,
Title: file.Title,
FileType: file.FileType,
ContentSize: file.ContentSize,
CreatedDate: file.CreatedDate
}));
}
})
.catch(error => {
this.boolerror=true;
});
}
}
XML File
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata" fqn="accountFiles">
<apiVersion>58.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__RecordPage">
<objects>
<object>Account</object>
</objects>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>
Sample UI