Download multiple Files & Documents as a ZIP file in Salesforce

If your requirement is to download multiple files in a zip in a Lightning component or Lightning Web Component or Visualforce page, then all you need to do is construct a URL which looks like this

here 068XXXXXXXXXXX1 is ContentVersion Id of file 1, 068XXXXXXXXXXX2 of file 2 and you can keep on adding as many file Ids as supported by URL length max URL length is (2,048) which means you can get 100~110 files like this at once depending upon the domain length of your org.

you can download a large file, by large I mean file with size 500mb+ easily.

Let’s create a Lightning Web Component which will download all the files in a ZIP file

Create an Apex Class RecordFileDownloaderController

public with sharing class RecordFileDownloaderController {

    public static List<Id> getfileIds(String recordId){
        Set<Id> contentDocumentIds = new Set<Id>();
        List<Id> contentVersionIds = new List<Id>();
        if(String.isNotBlank(recordId)) {
            for(ContentDocumentLink cdl : [SELECT ContentDocumentId,LinkedEntityId,ContentDocument.FileType FROM ContentDocumentLink WHERE LinkedEntityId =:recordId]) {

        if(contentDocumentIds.size() > 0) {
            for(ContentVersion cdv : [SELECT Id FROM ContentVersion WHERE isLatest = true AND ContentDocumentId IN :contentDocumentIds]) {

        return contentVersionIds;

Now Create a new Lightning Web Component recordFileDownloader

    <template if:true={error}>{error}</template>
    <a href={getDownloaLink} variant="brand" label="" title="Download Files" class="slds-button slds-button_brand">Download Files</a>
import { LightningElement, track, api} from 'lwc';
import getfileIds from '@salesforce/apex/RecordFileDownloaderController.getfileIds';

export default class RecordFileDownloader extends LightningElement {
    @api recordId;
    @track fileIds = '';
    @track error = '';
    connectedCallback() {

            recordId : this.recordId
        .then(result => {
            let fileDataList = JSON.parse(JSON.stringify(result));
            let fileIdsString = '';
            if(fileDataList) {
                for (let i in fileDataList) {
                    fileIdsString += fileDataList[i]+'/';
            if(fileIdsString.length > 0) {
                fileIdsString =fileIdsString.replace(/.$/,"?");
            this.fileIds = fileIdsString;
            this.error = undefined;
        .catch(error => {  console.log('error : '+JSON.stringify(error));
            this.error = error;
    get getDownloaLink() {
        return '/sfc/servlet.shepherd/version/download/'+this.fileIds;
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="" fqn="recordFileDownloader">
    <masterLabel>Mass File Downloader</masterLabel>
Mass file download LWC Component

refer this Git Repo for Code

Was this post useful? If yes then please share.

Leave a Comment

All fields marked with an asterisk (*) are required