function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ed.ax86Ed.ax86 

PHP, QueryMore issue and code example

Hi All, Im experiencing an odd but perhaps easy fix/oversight on using QueryMore.

1) My PHP code is trying to query all contacts ( 5000 + )
2) My code successfully seems to work partially. It works in 200 contact chunks Using QueryMore and prints the IDs out. ( Im printing them out for now..but when this works I will be doing other things )
BUT
3) Upon hitting 2000 it hangs in the browser ( does not continue printing anything )

My code looks like this: ( yes I left in the echos to see what Im doing right or wrong )
===========================

    $queryResult = $sfdc->query("select id, firstname, lastname, phone, fax from contact");
    $j=0;
    while ($queryResult->done == false)  {

        $records = $queryResult['records'];
        for( $i=0; $i<count($records); $i++){
            $contactId = $records[$i]->id;
            echo "<br> $j -".$contactId;
            $j++;
        }

        $locator = $queryResult['queryLocator'];
        echo "<h2>- $locator -</h2>";
        $queryResult = $sfdc->queryMore($locator);
    }

echo "Done";

===========================

To recap...this works fine in 200 unit chunks but hangs when the locator has reached 2000 as the locator ID looks like '01g5000000xxxxxxx-2000', so in my case only 2000 contacts are printed and the "Done" is never printed.

Thoughts on what I'm doing wrong?
Thanks!