0

I'm trying to collect data from Salesforce (from a custom object). I referenced generated Enterprise WSDL from Salesforce and referenced it to my web application.

I am pulling data from Salesforce and storing in a database, but only see 2,000 records.

Is there a way to pull more than 10,000 records from salesforce?

3

The QueryResult returned from client.query will have a queryLocator property and have the done attribute set to false if there are more records to return. You can use the queryLocator value in a client.queryMore to retrieve the next batch of records. You will need to continuously call client.queryMore until done is true. See the documentation for more information. They have an actual example written in C# that you can start from.


public void querySample() 
{
    try
    {
        QueryResult qr = null;
        binding.QueryOptionsValue = new sforce.QueryOptions();
        binding.QueryOptionsValue.batchSize = 250;
        binding.QueryOptionsValue.batchSizeSpecified = true;

        qr = binding.query("SELECT FirstName, LastName FROM Contact");

        bool done = false;
        int loopCount = 0;
        while (!done)
        {
            Console.WriteLine("\nRecords in results set " + 
                Convert.ToString(loopCount++)
                    + " - ");
            // Process the query results
            for (int i = 0; i < qr.records.Length; i++)
            {
                sforce.sObject con = qr.records[i];
                string fName = con.Any[0].InnerText;
                string lName = con.Any[1].InnerText;
                if (fName == null)
                    Console.WriteLine("Contact " + (i + 1) + ": " + lName);
                else
                    Console.WriteLine("Contact " + (i + 1) + ": " + fName
                        + " " + lName);
            }

            if (qr.done)
                done = true;
            else
                qr = binding.queryMore(qr.queryLocator);
        }
    }
    catch (SoapException e)
    {
        Console.WriteLine("An unexpected error has occurred: " + e.Message +
            " Stack trace: " + e.StackTrace);
    }
    Console.WriteLine("\nQuery execution completed.");
}

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