Salesforce Files stores and manages customer and business-related documents. We can share these documents with vendors whenever necessary to enhance customer satisfaction and services. However, Salesforce Files have a storage limit, so we should use storage properly. Salesforce released a feature to compress files in the Spring ’25 release. This blog will cover this feature to enhance performance with file compression in Apex.
Let us see what are the benefits of file compression in Salesforce.
- Reduced Storage Costs: Compressing files reduces storage costs; the smaller the file, the less storage it consumes saving you money in Salesforce. Compression helps businesses save on storage costs because attachments such as pictures or documents may consume considerable space.
- Faster Data Transfer: Less data will transfer faster. It’s incredibly helpful when uploading files via email or transferring data from one system to another, since it saves time for these activities. Better transfer speeds can speed up the overall workflow efficiency, users can improve the rate of access and sharing of information.
- Better User Experience: Users can enjoy a better experience with compressed files while downloading or sharing them. This is particularly important for those applications that use downloadable content because it increases user satisfaction and engagement.
- Enhanced File Management: File compression can also simplify processes of file management. For example, the creation of a compressed file to hold multiple files instead of saving them individually saves space and makes handling large sets of documents or attachments much easier for users.
- Efficient Use of Bandwidth: Compressed files use less bandwidth to be transmitted, which is good for companies with little internet allocation or working in locations that have slower connections. The result of this efficiency can be cost savings and improved performance.
Salesforce provided a Compression namespace to compress and decompress files with the help of Salesforce Apex. This namespace has a ZipWriter class that compresses given files and creates zip files.
The Compression namespace is added in the Salesforce Spring’24 release. Check out this post for other important features introduced in this release.
Let us use this class and create a generic class to compress files. Below steps are required to handle this requirement
- Create Generic File Compression Class
- Use Generic compression class
- Verify Zipped File
- Create Invocable class for Flow
1. Create Generic File Compression Class
Generic class FileCompressorService can handle different types of file compression. We can pass single file ID or multiple file version IDs for compression. We can also pass runtime blob data to compress it.
2. Use Generic compression class
We can use the above generic class to compress files. Method FileCompressorService.compressFiles will return a blob so we can utilize it wherever we want like sending email, attaching it to some record, or storing in some other storage location.
Run the above class from the Developer console and verify the sent files.
FileCompressorTest.sendZipFile();
3. Verify Zipped File
Verify the Zipped file sent in the email. It will contain compress files.

4. Create Invocable class for Flow
We need this feature in Salesforce Flow as well so we will create an apex class with InvocableMethod. This method will be exposed as Flow Action in Salesforce Flow.
We can add this method in the FileCompressorService class as well but we should separate different functionalities in different classes.
References
Similar Posts
- Top Developer Features in Salesforce Spring ’24 Release
- Object Initializer in Salesforce Apex
- Avoid Batch Apex and Use Queueable Class
- Generate and Create Signature in LWC
- Add Icon In Lightning Web Component Tab
- Schedule Email alerts based on Business Hours
- Send Email Template As PDF Attachment using Salesforce Apex
- Send Email Using Email Template and Apex
- Salesforce Spring ’25 Release: Top Flow Enhancements You Need to Know
- Salesforce Winter ’25 Release: Top Flow Enhancements You Need to Know
- Top 10 Enhancements in Salesforce Winter ’25 for Developers
- Ultimate Guide to Integrate Stripe with Salesforce CRM
Need Help?
If you need help implementing this feature, connect with me on my LinkedIn profile, Dhanik Lal Sahni.
1 Comment
It is good that we can zip blob data. Thank you for this article.