Zip attachments only with Apex in Salesforce

Before this post (about 2 years ago), I’d shared a post that is about how to zip attachments with JSZip and Apex in Salesforce, and recently I found a more simple way to do that thing, which is only using an Apex library named “Zippex” ( view on Github).

Here is the outline of my sample code:

1. Select attachments from an object id.
2. Zip those files with Zippex.
3. Save Blob data of zip file into a Document.
4. Redirect to Document download url and download it from Salesforce.

Let’s get started.

Prepare Attachments

Upload two Attachments to Account, e.g. apex PDF.pdf and apex Word.docx.


Upload Zippex library

Upload and compile Zippex library files ( view on Github) into your Salesforce organization.

Create sample class and page


It works fine for me : )

Apex zip sample page
You can download all of the above source files on my Github repository from HERE.

One more thing :

Before you decide to use this library in your project, make sure you have tested the cases of max number of files and max size of files, which may occur the Apex CPU Governor error.

Enjoy It!

Related Post

Pipeline for Salesforce – Be less busy, less... Overview Pipeline is a metadata deploy app for Salesforce, supports: ・Making Changeset with Excel file in seconds. ・Exporting Pipeline target metadata list to Excel file. ・No dependencies on Salesforce Org, deploying metadata between any different organizations. ・Deploying metadata base o...
Salesforce Mass Editor (Chrome Extension) – ... This's my second Chrome Extension (First one is HERE) this year, named "Salesforce Mass Editor" and it supports for doing the below things : ・Makes any Salesforce list view to be a powerful mass editor. ・Mass insert, mass clone, mass update, mass delete, ALL-IN-ONE. Support for both Classic and ...
Salesforce Smart Importer – 1-Drag to import... This is my third Chrome Extension named Salesforce Smart Importer (Other two popular extensions are Salesforce Mass Editor and Salesforce DevTools), it is designed for Salesforce not only admin but also normal user, supports : ・1-Drag to import any Excel / CSV data on anywhere in Salesforce, both ...
Setup an awesome Salesforce developer environment ... Why Sublime Text 3 ? I've been working with for about 2 years, and always using IDE(See here, Eclipse IDE Installation)as my development environment. I don't think it is really difficult to use, but it could be more friendly. For example: 1. It doesn't suppo...