2

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.

1 Answer 1

0

Don't think there's a definitive API for that, you'd have to do some rough calculations yourself.

  • Normal objects "weigh" 2 kB regardless how many long text / rich text fields they have.
  • Person accounts 4kB (Account+Contact; but that means you can just multiply totals of each by 2kB and all will work)
  • Campaign Members 3kB
  • Email Messages is where it stops working, the storage is "real", equal to length of the HTML body from what I remember.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.