LWC Quick Action: How to Download Records as Zip File in Minutes

By | December 13, 2023

In this blog post will walk you through the process of effortlessly downloading (Download Records as Zip File) connected records for all attachments with just one click. Utilizing a Headless Quick Action approach enables you to easily download records related file and all linked attachments as a zip file.

To achieve this, we will be using a headless quick-action approach.

Download Records as Zip File

  • Refer to the following code for implementation on the “Download Files” button that will be used for download records as zip file:
import { LightningElement, api, track } from 'lwc';
import getAttachement from '@salesforce/apex/DownloadAllAttacmentsZip.getAttachement';
import { NavigationMixin } from "lightning/navigation";

export default class DownloadZipQuickAction extends NavigationMixin(LightningElement) {
    @api recordId;
    @track AttachementIds = '';

    @api invoke() 
            .then(result => { 
                let fileList = JSON.parse(JSON.stringify(result));
                if (fileList != '') { 
                    for (let i in fileList) { 
                        this.AttachementIds += fileList[i] + '/';
                if (this.AttachementIds.length > 0) { 
                    this.AttachementIds = this.AttachementIds.replace(/.$/, "?");

                const config = {
                    type: 'standard__webPage',
                    attributes: {
                        url: '/sfc/servlet.shepherd/version/download/' + this.AttachementIds

            .catch(error => {
                console.log('Error::: ' + JSON.stringify(error));

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
        <targetConfig targets="lightning__RecordAction">


public with sharing class DownloadAllAttacmentsZip 
    public static List<Id> getAttachement(String recordId){
        Set<Id> contentDocIds = new Set<Id>();
        List<Id> contentVersionIds = new List<Id>();

        for(ContentDocumentLink cdl: [SELECT ContentDocumentId FROM ContentDocumentLink
                                        WHERE LinkedEntityId=:recordId])
            for(ContentVersion cv: [SELECT Id FROM ContentVersion 
                                    WHERE ContentDocumentId IN:contentDocIds 
                                    AND isLatest=true])
            return contentVersionIds;
            return null;
Download files Quick Action
Download files Quick Action
  • Output:
Download Records as Zip File
Downloaded files

By following the above blog instructions, you will be able to learn “How to Download Records as Zip File using the quick action button in the lightning web component?“. If you still have queries or any related problems, don’t hesitate to contact us at salesforce@greytrix.com.

More details about the Product are available on our website and Salesforce AppExchange.

We hope you may find this blog resourceful and helpful. However, if you still have concerns and need more help, please contact us at salesforce@greytrix.com.


Related Posts