
01-25-2008, 07:18 PM
|
|
Junior Member
|
|
Join Date: Jan 2008
Posts: 4
|
|
QueryMore returns 4 rows at a time
|
|
Hi,
I've got some code that's running a query that is returning well over 2000 rows. My code handles this fine, runs querymore, blah blah blah. THe problem is that once the initial 2000 rows are returned, each QueryMore returns only 4 rows at a time. E.G. I had a query that returned 3700 rows, it grabbed 2000 in the first pass then ran for about 90 minutes grabbing 4 rows every few seconds. Eventually it timed out or froze or I don't know what at row 3500. Maybe I'd hit my query limit?
Anyway, the point being, what's up with returning 4 rows? Anyone ever seen that?
-mb
|
|

01-29-2008, 06:40 AM
|
|
Administrator
|
|
Join Date: May 2007
Posts: 378
|
|
|
mb
Thanks for joining the site! Listen I had the same thing happen to me, but cannot remember what the problem is
Can you post some of your code so I, and others, can take a look at it?
|
|

02-01-2008, 01:24 PM
|
|
Junior Member
|
|
Join Date: Jan 2008
Posts: 4
|
|
I took out everything except the most basic parts. This code does nothing but query, cycle through and count each record, display how many records are being dealt with at a time, then query more until done.
~~~~~~~~~~~
|
PHP Code:
|
try { $wsdl = "partner.wsdl.xml"; $u = ""; $p = "";
$mySforceConnection = new SforcePartnerClient(); $mySoapClient = $mySforceConnection->createConnection(DIR_FS_SF_SOAP_CLIENT.$wsdl); $mylogin = $mySforceConnection->login($u,$p); $query = "Select c.Sales_Region__c, c.MailingState, c.MailingCountry, c.Id From Contact c WHERE c.Sales_Region__c = ''"; echo "<br>Query: ".$query."<br>"; $queryResult = $mySforceConnection->query($query); $totalQuerySize = $queryResult->size; echo "Total results from this query: ".$totalQuerySize."<br><hr><br><br>"; $numQueries = 1; // Checks response records if ($queryResult->size > 0) { $records = $queryResult->records; $record_count = 0; foreach ($records as $record) { $record_count++; $sContact = new SObject($record); $id = (string)$sContact->Id; $state = (string)$sContact->fields->MailingState; $country = (string)$sContact->fields->MailingCountry; $contacts[$record_count]['id']=$id; $contacts[$record_count]['state']=$state; $contacts[$record_count]['country']=$country; } $total_count = $record_count; echo "Examing ".$record_count."/".$totalQuerySize." records in pass #".$numQueries." Total records examined: ".$total_count."/".$totalQuerySize."<br>"; // Cycles through additional responses if the number of records // exceeds the batch size while (!$queryResult->done) { //unsetting just to be sure we don't get polluted data unset ($sObject); unset ($sObjects); unset ($contacts); unset ($records); $numQueries++; echo "Performing pass ".$numQueries."<br>"; $records = $mySforceConnection->queryMore($queryResult->queryLocator); $record_count = 0; foreach ($records as $record) { $record_count++; $sContact = new SObject($record); $id = (string)$sContact->Id; $state = (string)$sContact->fields->MailingState; $country = (string)$sContact->fields->MailingCountry; $contacts[$record_count]['id']=$id; $contacts[$record_count]['state']=$state; $contacts[$record_count]['country']=$country; } $total_count += $record_count; echo "Examing ".$record_count."/".$totalQuerySize." records in pass #".$numQueries." Total records examined: ".$total_count."/".$totalQuerySize."<br>"; } }
} catch (Exception $e) { echo $e->faultstring; }
|
|
|

02-04-2008, 10:27 AM
|
|
Administrator
|
|
Join Date: May 2007
Posts: 378
|
|
Bakum
I checked out your code and it looks okay to me, I cannot run it but I did create this script which works from my development account
|
PHP Code:
|
<?php ini_set("soap.wsdl_cache_enabled", "0"); require_once ('./includes/soapclient/SforcePartnerClient.php'); require_once ('./includes/soapclient/SforceHeaderOptions.php');
//Salesforce Connection information $wsdl = './includes/soapclient/partner.wsdl.xml'; $userName = "......"; $password = "......";
$client = new SforcePartnerClient(); $client->createConnection($wsdl); $loginResult = $client->login($userName, $password);
$soql = "Select Id, Name FROM Product2"; //Processes the query to get account information from Salesforce $records = get_records($client, $soql);
if ($records) { echo '<p>There are currently ' . count($records) . ' accounts:</p>';
//Loops through all records which come back from get_accounts function and //stores them into an array $pass_this foreach ($records as $r) { //echo '<pre>' . print_r($r,true) . '</pre>'; echo "The Id for this is <strong>" .$r->Id[0]. "</strong> with a product name of <strong>" .$r->any. "</strong><br />"; }
}
function get_records($connection,$query) { $queryOptions = new QueryOptions(500); $response = $connection->query(($query), $queryOptions); // check count to see if we are done if ($response->size > 0) { $records = $response->records; // Cycles through additional responses if the number of records // exceeds the batch size while (!$response->done) { set_time_limit(100); $response = $connection->queryMore($response->queryLocator); $records = array_merge($records, $response->records, $queryOptions); } }
return $records; }
?>
|
See if this helps at all, sorry I could not be more help man!
~Mike
|
|

02-04-2008, 03:11 PM
|
|
Junior Member
|
|
Join Date: Jan 2008
Posts: 4
|
|
|
No luck remembering how you fixed it in the past, eh?
|
|

02-08-2008, 07:25 AM
|
|
Administrator
|
|
Join Date: May 2007
Posts: 378
|
|
|
Man I tried to remember what it was but when I come across errors like this all I try and do is correct them as fast as possible and don't always list the errors or take notes on them. At least that was the way it was prior to starting this little site. So sorry about that
|
|
| Thread Tools |
|
|
| Rate This Thread |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 08:29 PM.
|
|
SEO by vBSEO 3.3.0 ©2009, Crawlability, Inc.