How to get detailed object storage size (KB/MB/GB) in Apex or via API?
I want to retrieve the detailed storage usage (in KB/MB/GB) for each object (both standard and custom) in Salesforce using Apex or any available API.
Currently, I can see this breakdown under: Setup → Storage Usage, but I cannot find a way to get the same information programmatically via Apex or REST API.
I have tried the following REST API:
/services/data/v58.0/limits/recordCount
This gives me the record count per object, but not the storage size. Since different objects have different average record sizes, just counting records is not accurate enough for tracking storage.
I want to store the detailed per-object storage usage over time, so I can monitor data growth and plan storage upgrades proactively.
What I've Found So Far The following Apex code gives total file storage usage at the org level:
`
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());
`
But again, this is only the total storage — not per-object.