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
ryanhca123ryanhca123 

Using AggregateResult query in PHP Toolkit gives error

I'm trying to run the following code and I'm getting the error shown below...

 

$conn = Salesforce::connect();

$active_users_query = "Select COUNT(Id) active_users From User Where isActive=true AND UserType = 'Standard'";
		
$a = $conn->query($active_users_query);
print_r($a);

error:

 

 

Warning: Invalid argument supplied for foreach() in /path_to_code/phpToolkit/soapclient/SforcePartnerClient.php on line 344
QueryResult Object
(
    [queryLocator] => 
    [done] => 1
    [records] => Array
        (
            [0] => SObject Object
                (
                    [type] => AggregateResult
                    [fields] => stdClass Object
                        (
                        )
                )
        )
    [size] => 1
)

 

not only is there a generated warning, I don't get the query result back...

 

 

(2 notes: [1] yes, the Salesforce::connect() method works. [2] running this query in the execute anonymous confirms that the query is valid)

 

Any ideas?

Alessandro Olivieri 4Alessandro Olivieri 4
$conn = Salesforce::connect();
$active_users_query = "Select COUNT(Id) active_users From User Where isActive=true AND UserType = 'Standard'";  
$a = $conn->query($active_users_query);
$queryResult = new QueryResult($a);
 for ($queryResult->rewind(); $queryResult->pointer < $queryResult->size; $queryResult->next()) {
            $record = $queryResult->current();
           echo $record->active_users;
             
        }