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.

Account

Upload Zippex library

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

Create sample class and page

ApexZipSampleController.cls

ApexZipSample.page

It works fine for me : )

Apex zip sample page
apex-zip-sample
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

Using URL parameters on Salesforce standard pages Salesforce has many URL parameters can be used on its standard page, with this kind of parameters, you can do some URL hacking on it, as below: Note: All of parameters must be encoded with UTF-8. Login page There are two ways to login and access into Salesforce from url. 1. https://
Setup an awesome Salesforce developer environment ... Why Sublime Text 3 ? I've been working with Force.com for about 2 years, and always using Eclipse+Force.com IDE(See here, Eclipse Force.com IDE Installation)as my development environment. I don't think it is difficult to use, but it could more friendly. For example: 1. It doesn't support APEX an...
Write Apex Test Classes efficiently with Tesforce 1.Why Tesforce The Test Classes are required to deploy Apex to a production environment or to be packaged and placed on Force.com AppExchange, it must provide at least 75% code coverage. That will be a huge workload to SFDC Developers if the project(application) include a lot of Apex Classes,the...
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. ・Export record data to CSV fi...