4

I'm trying to retrieve a list of Account objects from Salesforce using SOQL. Originally my query was this:

var result = service.query("SELECT Id, Name, RecordTypeId FROM Account");
return result.records.Select(record => record as Account).ToList();

However this only returns a maximum of 2,000 records and I have over that which I need to be returned by this query. After some digging around I found an example in Java which loops over the SOQL query which will allow a maximum of 10,000 records to be returned. I tried to replicate this in C# but it differs slightly, here is what I have now:

var accounts = new List<Account>();
foreach (Account account in service.query("SELECT Id, Name, Composer_ID__c, RecordTypeId FROM Account").records)
    accounts.Add(account);

return accounts;

However this still only returns a maximum of 2,000 records. How can I return more than 2,000 records by querying Account?

2 Answers 2

4

Seems you are using SOAP APIs, where by default the max records returned are 500, which could be uplifted to 2000. Best would be to use "queryMore" to load the records. Here is a post from salesforce docs with good code samples for the same: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_querymore.htm

1
  • 1
    You can also use the QueryResultIterator built-in code to handle query/queryMore for you automatically. It basically works like: var iterator = new sforce.QueryResultIterator(result); while(iterator.hasNext()) { var record = iterator.next(); /* do something with record */ }
    – sfdcfox
    Jul 2, 2013 at 13:36
7

I'm using simple_salesforce for python and ran into the same issue where there was a limit on the number of records returned. But that's because I was running sf.query(my_SOQL_query) instead of sf.query_all(my_SOQL_query). After running sf.query_all(my_SOQL_query), all 3,860 of my records were returned. (I previously instantiated Salesforce from the simple_salesforce library with sf = Salesforce(username=my_UN, password=my_pw, security_token=my_token).

You must log in to answer this question.

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