在PHP中从数组中获取obj
下面是我试图处理的SalesForce API查询的响应。我似乎不知道如何获取有关[Tasks]obj的任何信息。在PHP中。请参阅下面的API响应和现有代码。 正如您在下面看到的,我可以使用帐户信息,但不能使用任务信息在PHP中从数组中获取obj,php,arrays,object,salesforce,soql,Php,Arrays,Object,Salesforce,Soql,下面是我试图处理的SalesForce API查询的响应。我似乎不知道如何获取有关[Tasks]obj的任何信息。在PHP中。请参阅下面的API响应和现有代码。 正如您在下面看到的,我可以使用帐户信息,但不能使用任务信息 $query ="SELECT accountId,Status,Id,Service_Account_DMKT__r.name,(select id,Activity_Type__c,ActivityDate from Case.Tasks) from case where
$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>';
}
我也试过:
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);
看起来“任务”不是obj的名称,但我不知道它会是什么!
我用过:
对于第二个示例,我使用了Sammitch的答案,并将代码更新为:
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);
foreach($queryResult->记录为$case){
$accountId=$queryResult->current()->accountId;//从查询中提取accountId
$accountName=$queryResult->current()->Service\u Account\u DMKT\uuuu r->Name;//提取案例所在帐户的名称,请注意,当我们使用XXX\uu r.XXX时,我们在PHP中将其与->
$caseId=$queryResult->current()->Id;//从查询中提取caseId
回显“AccountId=”.$AccountId.”;
echo“accountName=”.$accountName.”;
回显“caseId=”.$caseId.”;
foreach($case->any['Tasks']->记录为$record){
$taskId=$record->Id[0];//这将正确返回数组中的第一个Id
//$taskType=$record->Activity\u Type\u\u c;//这不起作用,因为此信息位于不同的子对象“any”中
//$taskDate=$record->ActivityDate;//这也不起作用,因为它位于子对象“any”中
回显“taskId=”.$taskId.”;
echo“”.$record->any.”//注意,此对象可能看起来只是一个字符串,但此处有大量空白信息。您可以通过将其包装为json_encode($record->any)来查看它。
}
打印(盒);
我使用了上面的代码,然后通过使用strpos询问obj是否包含特定的字符串,我能够将字符串与它进行比较。这可能会让人很困惑,所以请注意!
$case->Tasks
不存在于给定的对象中,但是$case->any->Tasks
存在。我将其更新为:foreach($case->any->Tasks->records as$record){
但是我仍然得到响应:注意:试图获取非对象的属性
啊,any
是一个数组,而不是一个对象。所以:$case->any['Tasks']
成功了!谢谢!foreach($case->any['Tasks']->Tasks]->record->Id[0];
工作得很好!
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
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);