Created
October 28, 2020 03:30
-
-
Save karkranikhil/c64a2bd8a10445ac2d53fea6b42aff11 to your computer and use it in GitHub Desktop.
file preview and upload in lwc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public with sharing class filePreviewAndDownloadController { | |
| @AuraEnabled(cacheable=true) | |
| public static Map<ID, String> getRelatedFilesByRecordId(String recordId) { | |
| // Get record file IDs | |
| List<ContentDocumentLink> files = [SELECT ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = :recordId]; | |
| List<ID> fileIDs = new List<ID>(); | |
| for (ContentDocumentLink docLink : files) { | |
| fileIDs.add(docLink.ContentDocumentId); | |
| } | |
| List<ContentVersion> docs = [SELECT ContentDocumentId, FileExtension, Title | |
| FROM ContentVersion WHERE ContentDocumentId IN : fileIDs]; | |
| Map<ID, String> mapIdTitle = new Map<ID, String>(); | |
| for (ContentVersion docLink : docs) { | |
| mapIdTitle.put(docLink.ContentDocumentId, docLink.Title); | |
| } | |
| return mapIdTitle; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
making public