{"id":7789,"date":"2023-12-13T05:24:00","date_gmt":"2023-12-13T05:24:00","guid":{"rendered":"https:\/\/www.greytrix.com\/blogs\/salesforce\/?p=7789"},"modified":"2026-02-10T09:34:36","modified_gmt":"2026-02-10T09:34:36","slug":"download-records-as-zip-file","status":"publish","type":"post","link":"https:\/\/www.greytrix.com\/blogs\/salesforce\/2023\/12\/13\/download-records-as-zip-file\/","title":{"rendered":"LWC Quick Action: How to Download Records as Zip File in Minutes"},"content":{"rendered":"\n<p>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.<\/p>\n\n\n\n<p>To achieve this, we will be using a headless quick-action approach.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><em><span style=\"text-decoration: underline;\">Download Records as Zip File<\/span><\/em><\/strong><\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Refer to the following code for implementation on the \u201cDownload Files\u201d button that will be used for download records as zip file:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>downloadAllAsZipQuickActionbutton.html\n&lt;template&gt;\n&lt;\/template&gt;\ndownloadAllAsZipQuickActionbutton.js\nimport { LightningElement, api, track } from 'lwc';\nimport getAttachement from '@salesforce\/apex\/DownloadAllAttacmentsZip.getAttachement';\nimport { NavigationMixin } from \"lightning\/navigation\";\n\nexport default class DownloadZipQuickAction extends NavigationMixin(LightningElement) {\n  \n    @api recordId;\n    @track AttachementIds = '';\n\n    @api invoke() \n    {\n        getAttachement({\n            recordId:this.recordId\n        })\n            .then(result =&gt; { \n                let fileList = JSON.parse(JSON.stringify(result));\n                if (fileList != '') { \n                    for (let i in fileList) { \n                        this.AttachementIds += fileList&#91;i] + '\/';\n                    }\n                }\n                \n                if (this.AttachementIds.length &gt; 0) { \n                    this.AttachementIds = this.AttachementIds.replace(\/.$\/, \"?\");\n                }\n\n                const config = {\n                    type: 'standard__webPage',\n                    attributes: {\n                        url: '\/sfc\/servlet.shepherd\/version\/download\/' + this.AttachementIds\n                    }\n                };\n                this&#91;NavigationMixin.Navigate](config);\n\n            })\n            .catch(error =&gt; {\n                console.log('Error::: ' + JSON.stringify(error));\n             })\n    }\n}\n\ndownloadAllAsZipQuickActionbutton.cls\n&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;LightningComponentBundle xmlns=\"http:\/\/soap.sforce.com\/2006\/04\/metadata\"&gt;\n    &lt;apiVersion&gt;56.0&lt;\/apiVersion&gt;\n    &lt;isExposed&gt;true&lt;\/isExposed&gt;\n    &lt;targets&gt;\n        &lt;target&gt;lightning__RecordAction&lt;\/target&gt;\n    &lt;\/targets&gt;\n    &lt;targetConfigs&gt;\n        &lt;targetConfig targets=\"lightning__RecordAction\"&gt;\n            &lt;actionType&gt;Action&lt;\/actionType&gt;\n        &lt;\/targetConfig&gt;\n    &lt;\/targetConfigs&gt;\n&lt;\/LightningComponentBundle&gt;\n\nDownloadAllAttacmentsZip.cls\n\npublic with sharing class DownloadAllAttacmentsZip \n{\n    @AuraEnabled\n    public static List&lt;Id&gt; getAttachement(String recordId){\n        Set&lt;Id&gt; contentDocIds = new Set&lt;Id&gt;();\n        List&lt;Id&gt; contentVersionIds = new List&lt;Id&gt;();\n\n        for(ContentDocumentLink cdl: &#91;SELECT ContentDocumentId FROM ContentDocumentLink\n                                        WHERE LinkedEntityId=:recordId])\n                                        {\n                                            contentDocIds.add(cdl.ContentDocumentId);\n                                        }\n        if(contentDocIds.size()&gt;0){\n            for(ContentVersion cv: &#91;SELECT Id FROM ContentVersion \n                                    WHERE ContentDocumentId IN:contentDocIds \n                                    AND isLatest=true])\n                                    {\n                                        contentVersionIds.add(cv.Id);\n                                    }\n            return contentVersionIds;\n        }\n        else{\n            return null;\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/12\/1.-Download-files-Quick-Action.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/12\/1.-Download-files-Quick-Action.png\" alt=\"Download files Quick Action\"><\/a><\/center>\n<font size=\"2\"><center><i>Download files Quick Action<\/i><\/center><\/font>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Output:<\/li>\n<\/ul>\n\n\n\n<center><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/12\/2.-Downloaded-files.png\" target=\"_blank\" rel=\"noreferrer noopener\"><img decoding=\"async\" class=\"size-full\" style=\"border: 1px solid #A9A9A9; padding: 2px; margin: 2px; align: center;\" src=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-content\/uploads\/2023\/12\/2.-Downloaded-files.png\" alt=\"Download Records as Zip File\"><\/a><\/center>\n<font size=\"2\"><center><i>Downloaded files<\/i><\/center><\/font>\n\n\n\n<p>By following the above blog instructions, you will be able to learn <strong><em>\u201cHow to Download Records as Zip File using the quick action button in the lightning web component?\u201c<\/em><\/strong>. If you still have queries or any related problems, don\u2019t hesitate to contact us at salesforce@greytrix.com.<\/p>\n\n\n\n<p>More details about the Product are available on our website and Salesforce AppExchange.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p><em><strong><span style=\"text-decoration: underline;\">References:<\/span><\/strong><\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>https:\/\/developer.salesforce.com\/forums\/?id=9062I000000DMZCQA4<\/li>\n\n\n\n<li>https:\/\/www.salesforcebolt.com\/2023\/06\/reusable-download-all-files-as-zip.html<\/li>\n\n\n\n<li>https:\/\/salesforce.stackexchange.com\/questions\/307565\/how-to-download-files-documents-attachments-in-salesforce-via-apex<\/li>\n<\/ul>\n\n\n\n<p><strong>Related Posts<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>How to call Screen Flow from Lightning Web Component in Salesforce<\/li>\n\n\n\n<li>How to Upload Logo in Salesforce CPQ Template<\/li>\n\n\n\n<li>How to Use Static Resources In LWC<\/li>\n\n\n\n<li>How to call Screen Flow from Lightning Web Component in Salesforce<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.greytrix.com\/blogs\/salesforce\/2023\/12\/13\/download-records-as-zip-file\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[29,1559,100,108,890,1275,1274,1560,1557,1558,206,207,208,1278,385,394,1443],"class_list":["post-7789","post","type-post","status-publish","format-standard","hentry","category-salesforce-srv","tag-attachment","tag-attachment-download","tag-dynamic-filename","tag-email-attachment","tag-email-file-attachment","tag-emailfileattachment","tag-file","tag-file-download","tag-file-download-quick-action","tag-learn-lightning-web-component","tag-lightning","tag-lightning-basics","tag-lightning-component","tag-quick-action-button","tag-salesforce-auto-email-attachments","tag-salesforce-email-attachment","tag-upload-file"],"_links":{"self":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/7789","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/comments?post=7789"}],"version-history":[{"count":5,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/7789\/revisions"}],"predecessor-version":[{"id":12360,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/posts\/7789\/revisions\/12360"}],"wp:attachment":[{"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/media?parent=7789"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/categories?post=7789"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.greytrix.com\/blogs\/salesforce\/wp-json\/wp\/v2\/tags?post=7789"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}