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
colingcoling 

Problem getting counts with GROUP BY using php and partner wsdl - api version 20

Hi,

 

I am getting empty count results from a GROUP BY query executed through the php toolkit - using the latest partner wsdl (v20).

 

Here is the query:

 

SELECT LeadSource, COUNT(Id) from Lead  GROUP BY LeadSource

 

Using the php print_r function, here is a sample of the results returned in the response records. There is only one entry for [fields] - the count is not returned.

 

Array
(
    [0] => SObject Object
        (
            [type] => AggregateResult
            [fields] => stdClass Object
                (
                    [LeadSource] =>
                )

        )

    [1] => SObject Object
        (
            [type] => AggregateResult
            [fields] => stdClass Object
                (
                    [LeadSource] => Web
                )

        )

    [2] => SObject Object
        (
            [type] => AggregateResult
            [fields] => stdClass Object
                (
                    [LeadSource] => Phone Inquiry
                )

        )

...

 

Would the php toolkit have anything to do with this problem? Is there something else that I have missed?

 

Thanks in anticipation.

 

Colin G

 

NBlasgenNBlasgen

It's an Object, not an array:

 

foreach ($result as $subresult)

{

  $object = new SObject($subresult);

  print_r($object);

}

 

I think that's the right output, but you might need a `comma true` somewhere there.

colingcoling

This does not answer the question.

 

The statements that send the request are:

 

$query = "SELECT LeadSource, COUNT(Id) from Lead  GROUP BY LeadSource";

$queryOptions = new QueryOptions($query_limit);

$response = $sf_connection->query(($query), $queryOptions);

 

If I look at the $response in detail (I use the Eclipse debugger), I see it is an object (Object of: QueryResult) with the following structure:

 

queryLocator: null

done: true

records: an array of objects

size: 17 (ie. the records array has 17 items)

 

Looking at the first few entries in the records array, I see:

 

0: Object of: SObject

..type: AggregateResult

..fields: Object of: stdClass

....LeadSource: empty string

....<<<<<<<<<<<<< The count is nowhere to be seen

 

1: Object of: SObject

..type: AggregateResult

..fields: Object of: stdClass

....LeadSource: Web

....<<<<<<<<<<<<< The count is nowhere to be seen

 

2: Object of: SObject

..type: AggregateResult

..fields: Object of: stdClass

....LeadSource: Phone Inquiry

....<<<<<<<<<<<<< The count is nowhere to be seen

 

3: etc. etc.

 

 I hope this clarifies what I was trying to portray before. My apologies if I did not describe it clearly.

 

Thanks

 

Colin G

 

 

 

NBlasgenNBlasgen

I haven't used the new PHP library yet so sadly I guess I just don't know.  I've seen plenty of issues though when I first started developing with non-standard objects not showing up in results sets.  The first time I ran into this issue it was because I was using the Enterprise WSDL.  Switching to Partner fixed a lot.  Then the 2nd time I ran into the issue it was because PHP wasn't printing the entire contents of the array.  I had to take each record in the array and cast it as an SObject to be able to display the available fields.  I suspect the data is in there somewhere, it didn't just disappear.  I just don't know what the syntax is to get at it.  Slightly too new for me.

colingcoling

Thanks for your reply. It is still a mystery, so I have opened a case to see what they say.

 

I will post any solution(s) I find in this thread.

 

Thanks

 

Colin G

 

McFitz13McFitz13

Colin, did you ever figure this out? We are trying to get the record count per owner and running into similar issues.

Any help would be appreciated.

 

Thanks

 

Mike

colingcoling

Hi Mike,

I did open a case and communicate with Support over this. It seems that the php toolkit (20.0) does not support the result that comes back from this kind of query - I saw the counts being returned in the SOAP response, but they were lost by the time they got through to my application.

I have decided that I will use the REST API for this - and most likely other - types of queries. I might even migrate over to REST, once it is in production, for my app ('Lead Follow-Up').

 

I did a quick test for this query, and it was successful - I was able to retrieve the counts.

 

Query:

SELECT LeadSource, COUNT(Id) from Lead  GROUP BY LeadSource

 

Partial result from print_r:

17 record(s) returned<br/><br/>Array
(
[totalSize] => 17
[done] => 1
[records] => Array
(
[0] => Array
(
[attributes] => Array
(
[type] => AggregateResult
)

[LeadSource] =>
[expr0] => 5
)

[1] => Array
(
[attributes] => Array
(
[type] => AggregateResult
)

[LeadSource] => Web
[expr0] => 3
)

[2] => Array
(
[attributes] => Array
(
[type] => AggregateResult
)

[LeadSource] => Phone Inquiry
[expr0] => 3
)
...

I hope this helps.

 

Kind regards

 

Colin G

 

McFitz13McFitz13

Colin, appreciate the quick response.

That's unfortunate that it's not supported.

 

I wish SOQL didn't have so many restrictions....

 

Thanks for your help.

 

Mike