Zip attachments only with Apex in Salesforce
- Sep
- 07
- Posted by Lin
- Posted in APEX, Salesforce, Visualforce
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.
You can download all of the above source files on my Github repository from HERE.
Enjoy It!
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
ApexZipSampleController.cls
ApexZipSample.page
It works fine for me : )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!
Recent Posts
- Salesforce DevTools Release Notes (version 3.10.0) – mass edit custom fields on lightning
- Salesforce DevTools Release Notes (version 3.9.0) – Object Fields, SOQL Query Editor
- Salesforce DevTools Release Notes (version 3.8.0)
- Salesforce DevTools JUST HIT 10,000 USERS! THANK YOU!
- Using Promise for Apex Server-Side request in Lightning Component
Top Posts
- Salesforce DevTools – Powerful Salesforce developer tools, loved by over 50K developers - 222.8K views
- Date format and DateTime format - 206.9K views
- Salesforce Mass Editor (Chrome Extension) – Mass create, mass update, mass clone, mass delete on any list view. Support for both Classic and Lightning! - 159.6K views
- Setup an awesome Salesforce developer environment with Sublime Text 3 - 122.7K views
- Writing a Schedulable Batch Apex in Salesforce - 121.7K views
Categories
- APEX
- Apps
- Custom Label
- Custom Metadata
- Custom Setting
- Design & UI
- Event
- Heroku
- iOS & Object-c
- Lightnint Component
- Linux & Mac OS
- Metadata API
- Node.js
- Open Source
- Other
- PHP Framework
- Release Notes
- REST API
- Salesforce
- Salesforce DevTools
- Salesforce DX
- SOQL
- Tooling API
- Unit Tests
- Validation Rule
- Visualforce
- WordPress
You must be logged in to post a comment.