Skip to content

Instantly share code, notes, and snippets.

@karkranikhil
Created October 28, 2020 03:30
Show Gist options
  • Select an option

  • Save karkranikhil/c64a2bd8a10445ac2d53fea6b42aff11 to your computer and use it in GitHub Desktop.

Select an option

Save karkranikhil/c64a2bd8a10445ac2d53fea6b42aff11 to your computer and use it in GitHub Desktop.
file preview and upload in lwc
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;
}
}
@karkranikhil
Copy link
Author

making public

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment