viswajithkrishna / salesforce-dotnet

Automatically exported from code.google.com/p/salesforce-dotnet
0 stars 0 forks source link

List<T> function not working if number if items returned greater than _batchSize #12

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Dear Sir,

Thank you for publishing your library, which has proved a very useful "quick 
start". 

Unfortunately the List<T> function doesn't obtain all results (if there are 
more results than _batchSize). In order to get all results, you need to use the 
SalesForce "queryMore" function - I've rewritten the function accordingly:

public IEnumerable<T> List<T>(string query, params object[] args) where T : 
sObject {
    List<T> values = new List<T>();
    try {
        QueryResult queryResult = Query(query, args);
        if (queryResult.size > 0) {
            while (true) {
                values.AddRange(from record in queryResult.records select (T)record);
                if (queryResult.done)
                    break;
                else
                    queryResult = _binding.queryMore(queryResult.queryLocator);
            }
        }
    } catch (Exception ex) {
        Console.WriteLine("Failed to execute query succesfully: " + ex.Message);
    }
    return values;
}

Best regards, Ralph Purtscher

Original issue reported on code.google.com by ralphpur...@hotmail.com on 15 Dec 2010 at 11:25

GoogleCodeExporter commented 9 years ago
This method originally tries to make use of ConvertQueryResult in the 
SforceControllerBase class. My guess is that this method was originally 
intended to act as a proxy for handling the server side cursor.
I'd think that would be the preferred location to make the change, but I can't 
be certain as I don't know what the intended architecture of this project was.

Original comment by darkni...@gmail.com on 20 Jan 2011 at 11:13