This is a discussion on Get Child relationships within the Salesforce Coding Discussions forums, part of the Salesforce category; Hi,
I'm having a hard time getting to the child records of
-
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:
PHP Code:
<?php
$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->query & #8203;Locator);
$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:
Code:
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.
Last edited by mike; 09-28-2010 at 07:59 AM.
Reason: fix code blocks
-
What version of PHP are you using?
ALSO
There are other ways to get your data that you are wanting, but let's try to go from your PHP version
Thanks for joining the site BTW
~Mike
-
Solution
Mike,
Thanks for your reply. Have found a solution in the meantime. Posting it below in case others are interested:
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection/webservices/salesforceAPI/live_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, Description, 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";
$options = new QueryOptions(200);
$mySforceConnection->setQueryOptions($options);
$response = $mySforceConnection->query($query);
$queryResult = new QueryResult($response);
!$done = false;
foreach($queryResult->records as $result){$Id = $result->Id;
$Workshop_Stage__c = $result->fields->Workshop_Stage__c;
$activities_array = $result->queryResult;
if (is_array($activities_array)){
foreach ($activities_array as $key => $value ) {
$Activities_query_result = $result->queryResult[0];
$Activities = $Activities_query_result->records;
foreach($Activities as $Activity){
$AccountId = $Activity->fields->AccountId;
}
}//End loop
}else{}
}
Similar Threads
-
By alcom in forum Salesforce PHP Tutorials
Replies: 12
Last Post: 01-16-2010, 07:16 AM
-
By jarrettcoggin in forum Salesforce Coding Discussions
Replies: 3
Last Post: 08-04-2009, 08:01 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
Bookmarks