SELECT qualifiedapiname
FROM EntityDefinition 
WHERE IsQueryable = true 
  AND IsRetrieveable = true 
  AND IsDeprecatedAndHidden = false
LIMIT 2000

Above query lists all SFDC standard/custom objects. But it also returns objects which have no (zero) records at all and I want to skip/filter them. How can we ?

Is there any field/property metadata in Salesforce's EntityDefinition that can tell if the object has any records in it or if its empty/blank, something like "IsBlank or IsEmpty= true/false" ?

Expected output am looking for is:

Object Name RecordCount
Account 100
Lead 20
Opportunity 0

Looking at above output, I could filter Opportunity table further in the process since it doesn't have any records/rows yet.


1 Answer 1


Not sure if you need this information dynamically, or just periodically. You can get the information from the Rest API (use workbench or your favorite Chrome extension like Salesforce Inspector)

REST call


you can get either all record counts or specific objects...

this gives you a JSON return that you can work with.

   "sObjects" : [ {
     "count" : 3,
     "name" : "Account"
   }, {
     "count" : 10,
     "name" : "Contact"
   } ]
  • Excellent find! I wonder how I managed to miss this gem...
    – sfdcfox
    Nov 9, 2021 at 22:31
  • This is helpful. Thanks !!
    – ManiK
    Nov 10, 2021 at 7:15

You must log in to answer this question.

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