2

I'm using Salesforce.com Toolkit for PHP and I'm trying to output something I think is very simple.

THIS IS WORKING EXAMPLE CODE

$query = "SELECT ID, Phone FROM Contact LIMIT 5";
$response = $mySforceConnection->query($query);

foreach ($response->records as $record) {
echo $record->ID." - ".$record->Phone;
}

I'VE TWEAKED THE QUERY AND NOW WANT TO JUST OUTPUT THE NAME AND THE COUNT. HOWEVER THE CODE BELOW DOES NOT WORK

$query = "SELECT owner.name, count(type) FROM Task LIMIT 5";
$response = $mySforceConnection->query($query);

foreach ($response->records as $record) {
echo $record->owner.name; //DOES NOT WORK
}

THIS IS WHAT I GET WHEN I print_r ($record);

stdClass Object ( [Id] => [any] => Array ( [0] => First Last [1] => 2177 ) ) 

I just want to be able to output "First Last - 2177"

st4ck0v3rfl0w
  • 6,665
  • 15
  • 45
  • 48

1 Answers1

3
foreach ($response->records as $record)
{
    echo implode(' - ', $record->any);
}
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
  • Alix, If I wanted to get just the first name or just the count. How would I do that without implode? – st4ck0v3rfl0w May 01 '11 at 04:21
  • @st4ck0v3rfl0w: I *knew* you were going to ask that! :P Try `echo $record->any[0]` and `echo $record->any[1]`. – Alix Axel May 01 '11 at 04:23
  • You saved my day! I promise to make better use of caps next time :) – st4ck0v3rfl0w May 01 '11 at 04:25
  • @st4ck0v3rfl0w: Actually for the *first* name is a bit harder. `$name = array_filter(explode(' ', $record->any[0]), 'strlen'); $name_first = $name[0]; $name_last = $name[count($name) - 1];`. – Alix Axel May 01 '11 at 04:25