How to Fix This Problem
1. Use Chunk Upload (Recommended)
Rather than uploading the complete file in a single shot:
- Split the file into several smaller chunks
- Upload each chunk separately
- Combine them after upload
This avoids loading the full file into memory.
2. Use Salesforce File Upload Component
- Use the standard Lightning File Upload component
- It supports large files without Apex limits
This is the easiest and most reliable solution.
3. Upload Directly via REST API
Instead of sending the file through Apex:
- Upload the file directly using Salesforce REST API
- This bypasses Apex heap limitations
4. Use External Storage (If Needed)
- Upload files to external storage (AWS, Azure, etc.)
- Store only the reference or link in Salesforce
5. Avoid Full File Processing in Apex
- Convert large files fully into Base64 inside Apex
- Store large file data in variables
Process only what is necessary.