user989184
user989184

Reputation: 141

Trying to get property of non-object

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

Upvotes: 0

Views: 1881

Answers (2)

mogu
mogu

Reputation: 11

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') . ']');
}

Upvotes: 1

Sinthia V
Sinthia V

Reputation: 2093

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.

Upvotes: 0

Related Questions