Force.com-Toolkit-for-PHP
Force.com-Toolkit-for-PHP copied to clipboard
Query using GROUP BY returning non parsed data
Hi :)
I'm opening the issue as requested.
I was doing a query using GROUP BY and the result was a XML with namespace that can't be parsed.
Here is the query:
SELECT
Produto__r.Marca__r.Id,
Produto__r.Marca__r.Name,
Produto__r.Marca__c,
Produto__r.Marca__r.Id_Box__c
FROM
Veiculos__c
WHERE
Ativo__c = true
GROUP BY
Produto__r.Marca__r.Id,
Produto__r.Marca__r.Name,
Produto__r.Marca__c,
Produto__r.Marca__r.Id_Box__c
The result:
[
{
Id: [
"a02j00000046DZ7AAM",
"a02j00000046DZ7AAM"
],
any: "<sf:Name>Hyundai importados</sf:Name><sf:Marca__c>a02j00000046DZ7AAM</sf:Marca__c><sf:Id_Box__c>7</sf:Id_Box__c>"
},
{
Id: [
"a02j0000004kRhJAAU",
"a02j0000004kRhJAAU"
],
any: "<sf:Name>HB20</sf:Name><sf:Marca__c>a02j0000004kRhJAAU</sf:Marca__c><sf:Id_Box__c>5</sf:Id_Box__c>"
}
]
I'm using a workaround for now, basically I'm removing the sf: namespace from the xml tags, adding the xml declaration with a root node and loading it as a xml string something like:
$result = $query->records;
$objects = [];
foreach($result as $obj) {
$str = preg_replace('{sf:}', '', $obj->any);
$xml = '<?xml version="1.0" encoding="UTF-8"?><obj>'.$str.'</obj>';
$objects[] = simplexml_load_string($xml);
}
Best regards