Zip or Unzip Files in Salesforce


Hello Trailblazers,

Though Salesforce provides wide variety of out of the functionalities, in house solutions – creating a zip file or unzipping it in apex is still something that is not provided by Salesforce. For one of my work I came across situation where I wanted to zip multiple files together and I couldn’t find anything through Salesforce documentations. After spending some time over internet, I came across few workarounds which can be used to create zip files in Salesforce. 

Listing down three of them for three different platform solutions.

Zippex Utility

This is Apex based utility which can help you to zip files along with other useful operations. This utility code developed by Pedro Dal Col & Pliny Smith is available on GitHub and you can deploy it’s components directly to you org as well.
As per me this utility is very much powerful as it provides unzip feature as well. You can have folder structure as well or you can club multiple individual files as well using Zippex
Operations that are supported by Zippex are -
  • addFile
  • removeFile
  • getFile
  • containsFile
  • getFileNames
  • getFileInfo
  • getZipArchive
  • renameFile
  • unzipAttachment
But, because of the great powers listed above Zippex is more prone to CPU Time Limit Exceeded and Heap Size Limit Exceeded Salesforce exceptions. You might end up in error situation in most of the times so think twice before going for Zippex as solution to your problem.
Pro-Tip : You can always leverage additional limits of Asynchronous Apex 😊 


JSZip

We just saw how you can zip/unzip files using apex-based utility. Since there are some apex transactional limitations, you can switch to client side and use JSZip javascript library to create zip files within Salesforce. Since you execute these operations on client side you can get rid of Salesforce governor limits. 

You have to download script file from GitHub location and include it on your client component. Just like Zippex, JSZip also support multiple operations along with reading local file or file at some remote location. 

JSZip can help you to tackle apex limitations but it does have some limitations regarding browser compatibility, encoding support and issues with performance of your application.


File ZIPO

Apex has some limitations, JSZip also has some limitations then how to get stable solution for your product ? In this situation you can go for paid tools which are available in the market and can help you achieve your resolution. 

File ZIPO is a Salesforce native app that integrates your Salesforce org with the most-popular external cloud storage platforms such as Google Drive, OneDrive, Dropbox etc.

Along with file operations you can easily connect your Salesforce org with multiple cloud platforms. You can Sync files, merge files , backup your files to cloud storage or add files from cloud to Salesforce directly with File ZIPO.

This is paid app but I found it better than other apps available in terms of functionalities it is providing.


These three workarounds I found useful, do let me know in the comments if you know any other workarounds for zipping/unzipping files in Salesforce.

Thank you!

Comments

Popular posts from this blog

Salesforce Flow - Create multiple records from user input

Scan barcodes from Salesforce Mobile App