0

On my Contact Record Page I have created a Custom LWC to upload files. Based on the selected file type this performs some other downstream actions. We would like for all Users to only Upload Files via the this Component.

Additionally on the Contact Record Page I have the standard Files related list Component which includes an "Add Files" button. I am using this so Users can view the files and access the menu actions.
For Files it appears you cannot use a Dynamic Related list therefore you cannot remove the Actions.
Is there a creative way where I can remove the Add Files button?
I cannot remove permission as we still need users to upload files on other Objects. I could add a Files related List to my Upload Component, but I was looking to avoid re-creating all of the menu actions on the standard Files.

enter image description here

1
  • Hello Jeff. Can you please share the "File Types" solution that you do? Thanks! Commented Sep 9 at 13:18

1 Answer 1

2

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>

Final Result Sample UI

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .