function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
mansi gupta 30mansi gupta 30 

How to find current file storage used in apex

I have a requirement in wihich i need to check the used file storage of org.
How can i achieve this in apex, as i want to check if space are available in my org before inserting the attachment.
Khan AnasKhan Anas (Salesforce Developers) 
Hi Mansi,

Greetings to you!

You can get the storage information (Maximum and Remaining) using REST API Limit object.
  • Max is the limit total for the org.
  • Remaining is the total number of calls or events left for the org.
/services/data/v45.0/limits

Example response:
"FileStorageMB" : {
    "Max" : 20,
    "Remaining" : 20
  }

Please refer to the below link which might help you further with the above requirement.

https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/dome_limits.htm

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Thanks and Regards,
Khan Anas
mansi gupta 30mansi gupta 30
Actually, i have go through this before but i am looking if it possible to get the limits detail without using REST API in apex?
Khan AnasKhan Anas (Salesforce Developers) 
As per my knowledge, you have to use the API to get the limits.