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
Anila KhwajaAnila Khwaja 

Attachment Size per Object

Is there a way to find out what is the total attachment size per object in salesforce?
Best Answer chosen by Anila Khwaja
Fahad-AkhtarFahad-Akhtar
Hi Anila,
Below query will reutn you total bytes of file storage for a particular object, please repace opportunituy in below code with your object name

Use this link for more info on attachment object : https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_attachment.htm

Use this link to convert byte into GB : http://www.matisse.net/bitcalc/?input_amount=1&input_units=bytes&notation=legacy
SELECT count(BodyLength) FROM Attachment WHERE Parent.Type='Opportunity'

Thanks,
Fahad Akhtar

All Answers

Prabhat Kumar12Prabhat Kumar12
Anila,

Use bodyLenghth keyword to get the size of attachment.
 
select Id, Name, parentID, Description, bodyLength, LastModifiedDate from Attachment WHERE ParentId = :customObjectId

Let me know if you have any questions.
 
Fahad-AkhtarFahad-Akhtar
Hi Anila,
Below query will reutn you total bytes of file storage for a particular object, please repace opportunituy in below code with your object name

Use this link for more info on attachment object : https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_attachment.htm

Use this link to convert byte into GB : http://www.matisse.net/bitcalc/?input_amount=1&input_units=bytes&notation=legacy
SELECT count(BodyLength) FROM Attachment WHERE Parent.Type='Opportunity'

Thanks,
Fahad Akhtar
This was selected as the best answer
Anila KhwajaAnila Khwaja
Thanks Prabhat & Fahad. I believe there is no OOB way to find that out except querying it. Correct? 
Fahad-AkhtarFahad-Akhtar
That’s my understanding as well, if you have more than 50K attachments for your object, you can alternatively use data loader to export attachment records to excel, sum total body length and convert it to GB
Manish BattuManish Battu
SELECT count(BodyLength) FROM Attachment WHERE Parent.Type='Opportunity' would return the number of attachments per object.
In order to get the total size of the attachments per object
SELECT sum(BodyLength) FROM Attachment WHERE Parent.Type='Opportunity'