试图获取非对象的属性

发布于 2024-12-15 06:19:53 字数 1395 浏览 0 评论 0原文

我正在使用 Soapclient 将一些数据从 php 插入到名为 Application__c 的 salesforce 对象中。连接成功后,我编写了以下代码,

$applications = array();
    $updateFields = array();

                if($_POST['savingsAccountBankName'] != ''){
                    $updateFields['savings_account_bank_name__c']= $_POST['savingsAccountBankName'];
                }
if($_POST['AutoMake'] != ''){
                    $updateFields['Auto_make__c']= $_POST['AutoMake'];
                }
                if($_POST['AutoLicense'] != ''){
                    $updateFields['Auto_license__c']= $_POST['AutoLicense'];
                }
$sObject = new sObject();
            $sObject->type = 'Application__c';
            $sObject->fields = $updateFields;
            array_push($applications, $sObject);


            try {
                $results = $sforceClient->create($applications,'Application__c');
                foreach ($results as $result)
                {
                    $errMessage = $result->errors->message;
                    echo $errMessage;
                }
            } catch (Exception $e) {
                echo 'Salesforce Upsert Error. Please try again later.';
                echo '<pre>';
                print_r($e);
                echo '</pre>';
            }

我在“$errMessage = $result->errors->message;”行收到错误“尝试获取非对象的属性”。问题是什么?

谢谢

i am inserting some data to an salesforce object named as Application__c from php using Soapclient. After connection successfull, i have written following code

$applications = array();
    $updateFields = array();

                if($_POST['savingsAccountBankName'] != ''){
                    $updateFields['savings_account_bank_name__c']= $_POST['savingsAccountBankName'];
                }
if($_POST['AutoMake'] != ''){
                    $updateFields['Auto_make__c']= $_POST['AutoMake'];
                }
                if($_POST['AutoLicense'] != ''){
                    $updateFields['Auto_license__c']= $_POST['AutoLicense'];
                }
$sObject = new sObject();
            $sObject->type = 'Application__c';
            $sObject->fields = $updateFields;
            array_push($applications, $sObject);


            try {
                $results = $sforceClient->create($applications,'Application__c');
                foreach ($results as $result)
                {
                    $errMessage = $result->errors->message;
                    echo $errMessage;
                }
            } catch (Exception $e) {
                echo 'Salesforce Upsert Error. Please try again later.';
                echo '<pre>';
                print_r($e);
                echo '</pre>';
            }

i am getting error "Trying to get property of non-object" at line "$errMessage = $result->errors->message;". What is the problem?

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲念泪 2024-12-22 06:19:53

请注意 $result 是一个数组..

试试这个:

if (!isset($result[0]->success) || ($result[0]->success!=1)) {             

    $strErrCode = isset($result[0]->errors[0]->statusCode)?
                        $result[0]->errors[0]->statusCode:'CANNOT_INSERT';
    $strErrMsg = isset($result[0]->errors[0]->message)?
                       $result[0]->errors[0]->message:'Error Trying to insert';
    $arrResult = array(
                       'errorCode' => $strErrCode,
                       'errorMsg' => $strErrMsg,
                       'id' => '',
                      );
    error_log( 'Error Trying to insert  - [' . $strErrMsg . '] - [' . $strErrCode . ']');   
}
if (isset($result[0]->success) && ($result[0]->success==1)) {               
    $arrResult = array(
                       'errorCode' => 'SUCCESS_INSERT',
                       'errorMsg'  => 'Insert Success',
                       'id'        => isset($result[0]->id)?$result[0]->id:'1',
                      );

     error_log( 'Success insert - [' . (isset($result[0]->id)?$result[0]->id:'1') . ']');
}

Be aware that $result is an array..

Try this :

if (!isset($result[0]->success) || ($result[0]->success!=1)) {             

    $strErrCode = isset($result[0]->errors[0]->statusCode)?
                        $result[0]->errors[0]->statusCode:'CANNOT_INSERT';
    $strErrMsg = isset($result[0]->errors[0]->message)?
                       $result[0]->errors[0]->message:'Error Trying to insert';
    $arrResult = array(
                       'errorCode' => $strErrCode,
                       'errorMsg' => $strErrMsg,
                       'id' => '',
                      );
    error_log( 'Error Trying to insert  - [' . $strErrMsg . '] - [' . $strErrCode . ']');   
}
if (isset($result[0]->success) && ($result[0]->success==1)) {               
    $arrResult = array(
                       'errorCode' => 'SUCCESS_INSERT',
                       'errorMsg'  => 'Insert Success',
                       'id'        => isset($result[0]->id)?$result[0]->id:'1',
                      );

     error_log( 'Success insert - [' . (isset($result[0]->id)?$result[0]->id:'1') . ']');
}
缱倦旧时光 2024-12-22 06:19:53

这意味着无论 $results 包含什么,它都不是一个对象。尝试对变量 $results 执行 var_dump() 并查看其中实际内容。然后就可以正确引用了。

This means that whatever $results contains, it is not an object. Try doing a var_dump() on the variable $results and see what is actually in there. Then you can properly reference it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文