Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    • How to Use Graph API for Outlook-Salesforce Connection
    • Enhancing Performance with File Compression in Apex
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Friday, May 16
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Apex»Enhancing Performance with File Compression in Apex

    Enhancing Performance with File Compression in Apex

    Dhanik Lal SahniBy Dhanik Lal SahniJanuary 17, 2025Updated:January 19, 20251 Comment4 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    File Compression in Apex
    Share
    Facebook Twitter LinkedIn Pinterest Email

    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.

    1. 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.
    2. 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.
    3. 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.
    4. 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.
    5. 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

    1. Create Generic File Compression Class
    2. Use Generic compression class
    3. Verify Zipped File
    4. 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.

    File Compression in Apex | Zip Files in Salesforce | File Compression in Salesforce

    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

    • Compress and Extract Zip Files in Apex (Generally Available)
    • ZipWriter Class

    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.

    apex File Compression salesforce salesforce apex salesforce spring 25
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleSalesforce Spring ’25 Release: Top Flow Enhancements You Need to Know
    Next Article How to Use Graph API for Outlook-Salesforce Connection
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    By Dhanik Lal Sahni6 Mins Read

    Unlock the Power of Vibe Coding in Salesforce

    April 30, 2025
    By Dhanik Lal Sahni5 Mins Read

    How to Implement Dynamic Queueable Chaining in Salesforce Apex

    April 21, 2025
    View 1 Comment

    1 Comment

    1. Aakash on January 21, 2025 10:01 am

      It is good that we can zip blob data. Thank you for this article.

      Reply
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (110) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) einstein (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (29) Lightning web component (61) lwc (50) named credential (8) news (4) optimize apex (3) optimize apex code (4) Permission set (4) Queueable (9) rest api (23) S3 Server (4) salesforce (140) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (110) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) einstein (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (29) Lightning web component (61) lwc (50) named credential (8) news (4) optimize apex (3) optimize apex code (4) Permission set (4) Queueable (9) rest api (23) S3 Server (4) salesforce (140) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.