As the title says, I'm using a COUNT(id) query on some tables using the SOAP API. One of our tables is very large, and we're getting back QUERY_TIMEOUTs. Is there an easier way to figure out the size directly from the API? Assume I can't go into the front end at all.

  • Is that your full SOQL query? Just Count(Id) FROM [table]?
    – Mike Chale
    Dec 27 '12 at 20:51
  • Yes, I'm looking for the total row count of the table, straight from the SOAP API (we're using the Beatbox library), so Select Count(id) from [Table].
    – chowes
    Jan 2 '13 at 18:31

I'm curious to know the requirement for total row count on an object with no limiting WHERE clause. Can you elaborate on the use case?

A few common ways, the first which already gave you trouble:

Integer contactRows = [SELECT Count() FROM Contact];

You could also use a Summary Roll-up field on a parent object to aggregate the number of child records and then simply query this one field to get the total number of records. (sum a field on each record containing the number 1, 'the power of one')

  • The use case is strictly to find the number of rows in a table. The tables are not owned by us, but rather one of our clients. We periodically download this data (mostly just new rows, but occasionally full pulls of this data). The problem is when we try to pull the full data, we run into issues when there are a large # of rows. We'd like to know WHEN we're going to hit these issues by getting a row count in advance.
    – chowes
    Jan 2 '13 at 18:37

https://dataloader.io/ ..This app has a count in last step of export and it tells how much data excatly is in Database .

Edit after rethinking with REST

Not sure about SOAP API but fot rest API we definately can achieve this easily


This API first attribute is totalsize and this will definately give the exact count .

eg("totalSize" : 37)

All you need is use a REST API call within the salesforce with token as userinfo.sessionId().

  • This is interesting.. apparently the API is coming soon, so I will have to wait on that.
    – chowes
    Jan 2 '13 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.