Mass Attachments/Documents Download in Salesforce LWC

Isn’t it painful if you have multiple Attachments on a record and you have multiple such records and you need to download all attachments/Documents?

Clicking every record and then opening each attachment and clicking download is a long and fussy process.

This component is a dual component and it will work 2-way.

  1. Download mass Attachments of a particular record by adding component on the record lightning page.
  2. Bulk download Attachments of any Object by adding component on the non-record page.

Component Features:

  • Download attachments of any object.
  • Download attachments of a particular record only.
  • Pagination buttons to navigate.
  • Set custom record display size.
  • Filter attachments by Year/Month of any object.

Demo GIF:

  1. Record Lightning Page LWC Component

Mass Attachments LWC

2. Home Lightning Page LWC Component

Mass Files Download LWC

Screenshots:

Mass Files Attachment LWC Filter Mass Files Document Download LWC

Mass Files LWC Record Filter

 

Step-1: Create an Apex controller

Our apex controller will fetch the Object list if the component is added on the home lightning page and query the ContentDocument Records. Here we are using a wrapper class for object list which will return records in the form of value and label.

Create MassFilesDownloadController.cls Apex class.

Step-2: Now we will create the massFilesDownload Lightning Web Component.

For creating a new LWC component, you need to use the VS Code IDE.

Open the HTML file massFilesDownload.html and paste the below code.

 

Now open the JS file massFilesDownload.js and paste the below code.

 

Now paste the CSS in the massFilesDownload.css file.

 

Now open the meta file massFilesDownload.js-meta.xml and paste the below code.

 

Step-3: Now we will add the component on record Lightning Page.

  1. Go to the record where you want to put this component.
  2. Click on Setting Icon on top and click on Edit Page.
  3. Now on the Lightning Builder drop the massFilesDownload component from the left pane onto the screen.
  4. Save the page and Activate for Org Default and click on the back button.
  5. Your component is visible now on the screen.

Finally, our component is ready to use. You can change the record display size in the component. You can either download a single Attachment or bulk select the attachment and click on the download button on top.

Mass Attachments Download LWC

Bulk File LWC Download

Also Check:

Custom Lookup in LWC

Subscribe
Notify of
guest
12 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Pooja

Nice Post, Really Helpful in downloading Bulk Attachments of any Object but showing error on few Objects that this Object is not supported.

Ayush

Hello,

I hope you are doing.

Could you please let me know if this supports Opportunity?

Thanks.

Juan Sesan

Hi, how are you?

Could you please let me know if this supports Cases?

Thank you very much!

Juan Sesan

Hey thank you so much, it was realy useful.

Do you know what adjustment do i need to implement for download all the files in a zip?

Thank you again, have a nice day.

Regi Varghese

Hi Suyash,
Do you have the code for downloading all the files into a zip?

alex

hi,
nice work! I thought about improving UX little bit and wonder if you know any possibility to prevent redirects to new tabs in browser when we download multiple files?