[SalesForce] Is it possible to get data storage details of a Salesforce organization using Apex code

I am trying to get details of space used by several sObjects, Attachment and other using Apex code. I can get Attachments details but is there any possibility to get how much data has been consumed by an sObject e.g; Case, Lead etc..

In my opinion this may not possible. Any ideas ?

Best Answer

This has been made possible by now via the OrgLimits class [1].

Map<String,System.OrgLimit> limitsMap = OrgLimits.getMap();
System.OrgLimit fileStorage = limitsMap.get('FileStorageMB');
System.debug('Limit Name: ' + fileStorage.getName());
System.debug('Usage Value: ' + fileStorage.getValue());
System.debug('Maximum Limit: ' + fileStorage.getLimit());

You seem to be able to use the limit descriptors that are available via the REST API's limits resource [2].

[1] https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_System_OrgLimits.htm [2] https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_limits.htm

Related Topic