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
vdanvoye6596vdanvoye6596 

Get Child relationships

Hi,

I'm having a hard time getting to the child records of a query.  Here is what I have so far in my php script:

try {

  $mySforceConnection = new SforcePartnerClient();
  $mySoapClient = $mySforceConnection->createConnection("LINK_TO partner.wsdl.xml");
  $mylogin = $mySforceConnection->login($userName_live, $password_live);

  $query = "Select o.Id,o.Workshop_Stage__c, (Select Id, AccountId, WhoId, WhatId, Subject, IsTask, ActivityDate, OwnerId, Status, Priority, ActivityType, IsClosed, IsAllDayEvent, DurationInMinutes, Location, IsDeleted, CreatedDate, CreatedById, LastModifiedDate, LastModifiedById, SystemModstamp, CallDurationInSeconds, CallType, CallDisposition, CallObject, ReminderDateTime, IsReminderSet, Goal__c, Results__c, Actions__c, Comments__c, Visit_report__c, Goal_Classification__c, Link__c, Internet_Activity__c, Email_Name__c, Activity_Group__c From ActivityHistories) From OE_Registration__c o where o.Id='a0Q200000018zbMEAQ' LIMIT 10";

  $options = new QueryOptions(200);
  $mySforceConnection->setQueryOptions($options);
  $response = $mySforceConnection->query($query);
  $queryResult = new QueryResult($response);
  !$done = false;

  $record_size = $queryResult->size;

  if ($queryResult->size > 0) {

    while (!$done) {

      foreach ($queryResult->records as $record) {

  $Id = $record->Id;

  $Workshop_Stage__c = $record->fields->Workshop_Stage__c;

      }

      if ($queryResult->done != true) {

        echo "<br><br>***** Get Next Chunk *****<br><br>";

        try {
          $response = $mySforceConnection->queryMore($queryResult->queryLocator);
          $queryResult = new QueryResult($response);
        } catch (Exception $e) {

          print_r($mySforceConnection->getLastRequest());
          echo $e->faultstring;

        }
      } else {
        $done = true;
      }
    }
  }

} catch (Exception $e) {
  print_r($mySforceConnection->getLastRequest());
  echo $e->faultstring;

}

 

How would I access the AccountId field from the ActivityHistories object?

 

The output produced looks like:

 

SObject Object
(
    [type] => OE_Registration__c
    [fields] => stdClass Object
        (
            [Workshop_Stage__c] => Taken in Forecast
        )

    [Id] => a0Q200000018zbMEAQ
    [queryResult] => Array
        (
            [0] => QueryResult Object
                (
                    [queryLocator] => 
                    [done] => 1
                    [records] => Array
                        (
                            [0] => SObject Object
                                (
                                    [type] => ActivityHistory
                                    [fields] => stdClass Object
                                        (
                                            [AccountId] => 001200000017DNgAAM
                                        )

                                )

                            [1] => SObject Object
                                (
                                    [type] => ActivityHistory
                                    [fields] => stdClass Object
                                        (
                                            [AccountId] => 001200000017DNgAAM
                                        )

                                )

                            [2] => SObject Object
                                (
                                    [type] => ActivityHistory
                                    [fields] => stdClass Object
                                        (
                                            [AccountId] => 001200000016lrhAAA
                                        )

                                )

                            [3] => SObject Object
                                (
                                    [type] => ActivityHistory
                                    [fields] => stdClass Object
                                        (
                                            [AccountId] => 001200000017DNgAAM
                                        )

                                )

                        )

                    [size] => 4
                )

        )

)

 

Many thanks for any light you can shed on this for me!  Been struggling for hours and about to give up.