Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ForEach循环反复返回相同的名称_Php_Arrays_Object_Salesforce - Fatal编程技术网

Php ForEach循环反复返回相同的名称

Php ForEach循环反复返回相同的名称,php,arrays,object,salesforce,Php,Arrays,Object,Salesforce,每当我通过SalesForce PHP api运行此代码时,它都会失败,错误为:注意:尝试获取非对象的属性 $query ="SELECT accountId,Status,Id,Service_Account_DMKT__r.name,(select Activity_Type__c from Tasks) from case where Owner.Name ='" . $name . "' AND CreatedDate = THIS_MONTH AND Record_type_n

每当我通过SalesForce PHP api运行此代码时,它都会失败,错误为:注意:尝试获取非对象的属性

    $query ="SELECT accountId,Status,Id,Service_Account_DMKT__r.name,(select Activity_Type__c from Tasks) from case where 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); 
      foreach($queryResult->records as $case){ 
        //for ($queryResult->rewind(); $queryResult->pointer < $queryResult->size; $queryResult->next()) {    
        $callCounter = 0;
        $emailCounter = 0;
      $accountId = $case->current()->accountId; 
      $accountName=$case->current()->Service_Account_DMKT__r->Name;
      $caseId= $case->current()->Id; 


      if($case->any['Tasks']->records) { 
      $counter=0;       
      foreach($case->any['Tasks']->records as $record) {         
          $taskRecord = $record->any;
          if (strpos($taskRecord, 'Call - Outbound') !== false) {
            $callCounter++;
        } else {
          $emailCounter++;
        }
        $counter++;
        }
      }
      echo '<p>AccountName=' . $accountName . '</p><p>CaseId=' . $caseId . '</p>';
        echo '<p>' . $callCounter . ' Calls and ' . $emailCounter . ' emails';
        echo'<hr>';
        $index++;
      }

print_r($case);
但我不确定用什么来代替电流。下面是来自SF API的响应对象

stdClass Object
(
[type] => Case
[Id] => Array
    (
        [0] => 5000e00001J7L0pAAF
        [1] => 5000e00001J7L0pAAF
    )

[any] => Array
    (
        [0] => 00130000002bqXiAAIClosed - Contact Declined5000e00001J7L0pAAF
        [Service_Account_DMKT__r] => stdClass Object
            (
                [type] => Account
                [Id] => 
                [any] => brinsoncorsicanafordfd
            )

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

                    )

                [size] => 1
            )

    )

)

我最终通过将响应转换回另一个对象来修复它

$query ="SELECT accountid,Status,Id,Service_Account_DMKT__r.name,(select Activity_Type__c,subject from Tasks) from case where Owner.Name ='" . $SFName . "' AND CreatedDate = THIS_MONTH AND Record_type_name__c='Performance Reviews' AND status NOT IN ('')";
    $response = $mySforceConnection->query($query);
    $queryResult = new QueryResult($response); 
      foreach($queryResult->records as $case){  //For every record within $queryResult
        $callCounter = 0;                       //Set up our task counters
        $emailCounter = 0;
        $sObject = new SObject($case); //turn $case back into a SObj to easy step thru
        $accountId= $sObject->AccountId; //Pull AccountId from $sObject
        $accountName=$sObject->Service_Account_DMKT__r->Name;
        $caseId=$sObject->Id;
        $caseStatus=$sObject->Status;
      if(!isset($sObject->queryResult)) { //Check if there are any tasks on the record, otherwise we'll get an error
        $callCounter=0; //if there are no tasks, set counters to 0
        $emailCounter=0;
      }else{
      $counter=0;
      foreach($case->any['Tasks']->records as $record) {  //for each task in the $case 
        $taskObject = new SObject($record);      //Turn $record into taskObject so we can step through it.
         $taskType = $taskObject->Activity_Type__c; //Pull the activity type out of TaskObject
         if($taskType == "Call - Outbound"){ //Calling $taskType actually allows us to compare the obj to a string, where as going through this in an array format would not!
           $callCounter++; //increase counter if the taskType is a call
       } else {
         $emailCounter++;
       }            
       }    
       }
       echo '<p>AccountName=' . $accountName . '</p><p>AccountID=' . $accountId . '</p><p>CaseId=' . $caseId . '</p><p>CaseStatus=' . $caseStatus . '</p>';
       echo '<p>' . $callCounter . ' Calls and ' . $emailCounter . ' emails';
       echo'<hr>'; 
     }

哪一个是非对象?那是哪条线?它是当前的返回,还是$case本身,还是服务帐户\u DMKT\r?调试它,做一些var_转储!考虑到刚才的$case->current,这个$queryResult->current感觉很奇怪。即使在您的输出中,嵌套数组也没有这个调用的名称值$case->current->Service\u Account\u DMKT\u r->Name;挑战在于我无法正确输出这三行代码。在最后一行使用$queryresult是一个输入错误,应该是$case。我的问题是我不知道如何单步通过对象从$case到Name$case基本上只是$queryResult->recordsAlso,非对象是所有三行,因为我没有正确地通过对象。我很好奇是否有其他人可以提供更好的解决方案
$query ="SELECT accountid,Status,Id,Service_Account_DMKT__r.name,(select Activity_Type__c,subject from Tasks) from case where Owner.Name ='" . $SFName . "' AND CreatedDate = THIS_MONTH AND Record_type_name__c='Performance Reviews' AND status NOT IN ('')";
    $response = $mySforceConnection->query($query);
    $queryResult = new QueryResult($response); 
      foreach($queryResult->records as $case){  //For every record within $queryResult
        $callCounter = 0;                       //Set up our task counters
        $emailCounter = 0;
        $sObject = new SObject($case); //turn $case back into a SObj to easy step thru
        $accountId= $sObject->AccountId; //Pull AccountId from $sObject
        $accountName=$sObject->Service_Account_DMKT__r->Name;
        $caseId=$sObject->Id;
        $caseStatus=$sObject->Status;
      if(!isset($sObject->queryResult)) { //Check if there are any tasks on the record, otherwise we'll get an error
        $callCounter=0; //if there are no tasks, set counters to 0
        $emailCounter=0;
      }else{
      $counter=0;
      foreach($case->any['Tasks']->records as $record) {  //for each task in the $case 
        $taskObject = new SObject($record);      //Turn $record into taskObject so we can step through it.
         $taskType = $taskObject->Activity_Type__c; //Pull the activity type out of TaskObject
         if($taskType == "Call - Outbound"){ //Calling $taskType actually allows us to compare the obj to a string, where as going through this in an array format would not!
           $callCounter++; //increase counter if the taskType is a call
       } else {
         $emailCounter++;
       }            
       }    
       }
       echo '<p>AccountName=' . $accountName . '</p><p>AccountID=' . $accountId . '</p><p>CaseId=' . $caseId . '</p><p>CaseStatus=' . $caseStatus . '</p>';
       echo '<p>' . $callCounter . ' Calls and ' . $emailCounter . ' emails';
       echo'<hr>'; 
     }