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
Jim AndersonJim Anderson 

Access RelationShip Query results

Can any one tell me how to access Contact.Name form my code below, you can see I'm echo out a few different ways but nothing seems to work:
 
$strSQL = "SELECT Id,AssetId,AccountId, Contact.FirstName, ";
$strSQL .= "CaseNumber,Subject,Status,CreatedDate,What_is_your_acronym__c,Which_product__c ";
$strSQL .= "FROM Case ORDER BY Id DESC LIMIT 2 ";
 
   $Result = $mySforceConnection->query($strSQL);
 
 if ($Result->size == 0) {
  NoRecords(0);
 }else{
 
  $records = $Result->records;
  
  foreach ($records as $record) {
  
      $sObject = new SObject($record);
   
   echo $sObject->fields->CaseNumber.":: ";
   echo $sObject->fields->Contact->FirstName."<br>";
   echo $sObject->fields->FirstName;
  }
 }
sissyphussissyphus

Did you ever get a reply to your question from '07? I'm actually up the same creek right now. I'm basically stuck on how to refer to stuff that was requested through dot-syntax.

 

  $query   = 'SELECT Sales_Region__c, Sales_Area__c, Owner.Name, OwnerId, StageName, Amount FROM Opportunity WHERE IsWon = FALSE LIMIT 10';
  $queryOptions = new QueryOptions(500);
  $response  = $connection->query(($query), $queryOptions);
  $records = $response->records;

  foreach ($records as $r)

  $r = new SObject($r);

Then... $r->fields->Sales_Region__c ...

is an example of how to refer to the regular fields, but I can't figure out how to refer to the field "Owner.Name" in PHP

I can find in if I print out "$records" using "print_r" but I can't figure out how to refer to it once it's embedded in the SObject

 

 

 

Jim AndersonJim Anderson

$sObject->sobjects[0]->fields->FirstName worked for me. So for you try:

 

$r->sobjects[0]->fields->Name

Jim AndersonJim Anderson

Also in your example:

 

foreach ($records as $r)

  $r = new SObject($r);

 
 
Not sure you want to use $r = new SObject($r), you are already using $r in foreach ($records as $r) so if you have more then one record it would break.