When using Email-to-case in Salesforce, most of the time we may hit the org storage limit, since # of emails are increasing day by day. Here are the few options to increase the org storage.Â
- Delete the Unnecessary/old files & data
- Get additional Storage
- Archive old files/Data
Here, we are going to see the last option: Archive the Email Message records (for the older closed cases) to increase the org storage.
We have a custom Option to archive Emails using Apex.
Flow for the implementation:
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-51-1024x295.png)
We can schedule the batch class daily to automatically archive the emails and free up some space in our Salesforce org.
Demo:
Case before archiving:
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-51.png)
Case Emails Before Archiving:
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-51-1024x295.png)
Case Email Message Files:
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-51-1024x295.png)
Case Chatter post Before Archiving:
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-51.png)
Execute the batch:
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-51-1024x218.png)
Case Record After Archiving:
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-53.png)
Case Emails After archiving:
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-52-1024x158.png)
Files After Archiving:
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-54-1024x234.png)
Case Comments After Archiving:
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-55.png)
Created PDF:
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-55-1024x353.png)
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-56-1024x357.png)
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-58-1024x364.png)
Email after batch completed:
![](https://www.mstsolutions.com/wp-content/uploads/2022/04/image-57.png)
Limitations:
- Even though archiving reduces data storage, our PDF files occupied the org files storage. In step 2, we need to move the created Pdf from Salesforce by using s3- link and other similar managed packages.
Advantages:
- Within the single PDF document, an agent can get 360 views & detailed history of the case. They can see the emails, attachments, Chatter details within the pdfs.
Sample Code:
Please refer to the GitHub link below for full code: https://github.com/kanchanaraju/EmailArchivingSF