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 ?


2 Answers 2


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


There is no API for this currently, either Apex or otherwise, one could envision it one day being part of the Metadata API (or Tooling API?) perhaps, but currently not. The only programatic way to do this would be to screen scrape the information from the Data Storage page yourself in Apex code. Its far from ideal but could be done if you are happy with the risks (e.g. the HTML changing in future platform releases or fixes and you have to tweak your parsing logic). Here is a post from Metadaddy describing the process and the warnings... screen scrape Salesforce with REST GET call from Apex

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .