How to Fix This
1. Avoid Uploading Large Files Through Apex
Apex is not built for large file uploads directly. When the file is large, do not upload it via Apex at all.
2. Use Standard Salesforce File Upload
- Use the standard Salesforce file upload component
- It supports large files and handles everything without hitting Apex limits
It is the easiest and most foolproof way.
3. Upload Files in Parts (Chunking)
Rather than submitting the entire file at once:
- Break the file into smaller chunks
- Upload each part separately
- Combine them after upload
This avoids memory overflow.
4. Use Direct API Upload
If you’re working with integrations:
- Upload the file directly using Salesforce REST API
- Skip passing the file through Apex
This helps bypass heap limitations.
5. Use External Storage for Large Files
- Upload them for external storage (i.e. AWS , Google Drive, and so on ).
- Store only the link or reference in Salesforce