Получение объекта из массива в переполнении стека

У меня есть ответ ниже на запрос SalesForce API, с которым я пытаюсь работать. Я не могу понять, как собрать какую-либо информацию, касающуюся [Задач] объекта. в PHP. См. Ниже ответ API & существующий код.
Как вы можете видеть ниже, я могу работать с информацией об учетной записи, но не с информацией о задании.

$query ="SELECT accountId,Status,Id,Service_Account_DMKT__r.name,(select id,Activity_Type__c,ActivityDate from Case.Tasks) from case where Service_Account_DMKT__r.name='budcrossfordfd' AND Owner.Name ='".$name."' AND CreatedDate = THIS_MONTH AND Record_type_name__c='Performance Reviews' AND status NOT IN ('')";
$response = $mySforceConnection->query($query);
$queryResult = new QueryResult($response); //We collected the response from our SF Query
$counter=0;
for ($queryResult->rewind(); $queryResult->pointer < $queryResult->size; $queryResult->next()) {
$counter++;
$accountId = $queryResult->current()->AccountId; //Pulls accountId from Query
$accountName=$queryResult->current()->Service_Account_DMKT__r->Name; //pulls the name of the account the case exists on, note that when we use XXX__r.XXX, we sep. this in PHP with ->
$caseId= $queryResult->current()->Id; //Pulls CaseId from Query
$taskType=$queryResult->current()->Tasks->Activity_Type__c; //Pulls the Type of the Task that exists under the Case (This isn't working!)
$taskId= $queryResult->current()->Tasks->Id; //Pulls Task Id (This isn't Working!)
$taskDate=$queryResult->current()->Tasks->Activity_Date; //Pulls date the Task was Created (This isn't Working!)
echo'<p>AccountId=' . $accountId . '</p>';
echo'<p>accountName=' . $accountName . '</p>';
echo'<p>caseId=' . $caseId . '</p>';
echo'<p>taskType=' . $taskType . '</p>';
echo'<p>taskId=' . $taskId . '</p>';
echo'<p>taskDate=' . $taskDate . '</p>';
}

Отклик :

Notice:  Trying to get property of non-object in Z:\web\phpToolKit\test\partner.php on line 65



Notice:  Trying to get property of non-object in Z:\web\phpToolKit\test\partner.php on line 66



Notice:  Trying to get property of non-object in Z:\web\phpToolKit\test\partner.php on line 67

AccountId=0016000000NsN3uAAF

accountName=budcrossfordfd

caseId=5000e00001J7KtpAAF

taskType=

taskId=

taskDate=

QueryResult Object
(
[queryLocator] =>
[done] => 1
[records] => Array
(
[0] => stdClass Object
(
[type] => Case
[Id] => Array
(
[0] => 5000e00001J7KtpAAF
[1] => 5000e00001J7KtpAAF
)

[any] => Array
(
[0] => 0016000000NsN3uAAFClosed - Approved5000e00001J7KtpAAF
[Service_Account_DMKT__r] => stdClass Object
(
[type] => Account
[Id] =>
[any] => budcrossfordfd
)

[Tasks] => stdClass Object
(
[done] => 1
[queryLocator] =>
[records] => Array
(
[0] => stdClass Object
(
[type] => Task
[Id] => Array
(
[0] => 00T0e00006GH5Q2EAL
[1] => 00T0e00006GH5Q2EAL
)

[any] => Call - Outbound2018-04-04
)

[1] => stdClass Object
(
[type] => Task
[Id] => Array
(
[0] => 00T0e00006GGNgEEAX
[1] => 00T0e00006GGNgEEAX
)

[any] =>
)

)

[size] => 2
)

)

)

)

[size] => 1
[pointer] => 1
[sf:QueryResult:private] =>
)

Я также попробовал:

foreach($queryResult->records as $case){
$accountId = $queryResult->current()->AccountId; //Pulls accountId from Query
$accountName=$queryResult->current()->Service_Account_DMKT__r->Name; //pulls the name of the account the case exists on, note that when we use XXX__r.XXX, we sep. this in PHP with ->
$caseId= $queryResult->current()->Id; //Pulls CaseId from Query
echo'<p>AccountId=' . $accountId . '</p>';
echo'<p>accountName=' . $accountName . '</p>';
echo'<p>caseId=' . $caseId . '</p>';

foreach($case->Tasks->records as $record) {
$taskId=$record->Id;
$taskType=$record->Activity_Type__c;
$taskDate=$record->ActivityDate;
echo'<p>taskId=' . $taskId . '</p>';
echo'<p>taskType=' . $taskType . '</p>';
echo'<p>taskDate=' . $taskDate . '</p>';
}
print_r($case);

Который возвращается

AccountId=0016000000NsN3uAAF

accountName=budcrossfordfd

caseId=5000e00001J7KtpAAF



Notice:  Undefined property: stdClass::$Tasks in Z:\web\phpToolKit\test\partner.php on line 69



Notice:  Trying to get property of non-object in Z:\web\phpToolKit\test\partner.php on line 69



Warning:  Invalid argument supplied for foreach() in Z:\web\phpToolKit\test\partner.php on line 69

Похоже, что «Задачи» не имя объекта, но я не могу понять, что это будет вместо этого!
Я использовал: Salesforce PHP Toolkit — получение данных из вложенного запроса SOQL
для моего второго примера

0

Решение

Я использовал ответ Саммитча и обновил код:

foreach($queryResult->records as $case){
$accountId = $queryResult->current()->AccountId; //Pulls accountId from Query
$accountName=$queryResult->current()->Service_Account_DMKT__r->Name; //pulls the name of the account the case exists on, note that when we use XXX__r.XXX, we sep. this in PHP with ->
$caseId= $queryResult->current()->Id; //Pulls CaseId from Query
echo'<p>AccountId=' . $accountId . '</p>';
echo'<p>accountName=' . $accountName . '</p>';
echo'<p>caseId=' . $caseId . '</p>';

foreach($case->any['Tasks']->records as $record) {
$taskId=$record->Id[0]; //This correctly returns the first ID in the array
//$taskType=$record->Activity_Type__c; //This doesn't work because this information  is located in a different sub obj "any"//$taskDate=$record->ActivityDate; //This also doesn't work because it's located in a sub object "any"echo'<p>taskId=' . $taskId . '</p>';
echo '<p>' . $record->any . '</p>' //watch out, this object might look to only be a string, but there is a lot of white space info in here. you can see it by wrapping it in json_encode($record->any).
}
print_r($case);

Я использовал приведенный выше код, а затем смог сравнить строку с ней, используя strpos, чтобы спросить obj, содержит ли она конкретную строку. Это может быть очень запутанным, так что будьте осторожны!

0

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]