Salesforce API: error on & # 8594; update (), "INVALID_TYPE: should send a specific type of object."

I studied this and tried many options based on my understanding of how to update a record in SObject, but I keep getting the following error:

SoapFault exception: [sf: INVALID_TYPE] INVALID_TYPE: A specific object type must be sent. in / home / public _html / soapclient / SforceBaseClient.php: 509

I can successfully log in to the page, but when I execute the code below, I get the above error.

    $fieldsToUpdate = array (
        "Name"=>$_POST['Name']
    );

    $sObject = new SObject();
    $sObject->Id = $_POST['prospectID']; // this is the Id of the record
    $sObject->fields = $fieldsToUpdate;
    $sObject->type = 'Prospect__c'; // this is the API name of custom object

    try {
        $response = $mySforceConnection->update($sObject);
    } catch (Exception $e) {
        echo $e;
    }

I am using PHP Toolkit 13.0 from the Force.com developer documentation, but I can not understand this error. In addition, I use Enterprise WSDL in sandbox mode and set the correct wsdl xml.

Thank.

+3
source share
3

sObject - Salesforce, . API (SOAP) , sObject. (Lead, Contact Account )

update().

+1

update(). , update() , :

$response = $mySforceConnection->update(array($object), 'Prospect__c');

, - , , StdClass:

$prospect = new StdClass();
$prospect->Id = '006....';
$prospect->Name 'Foobar';
$response = $mySforceConnection->update(array($prospect), 'Prospect__c');

FYI, , , . Salesforce - (.. ). Salesforce SOAP, , .

+1

if you use Partner wsdl

 <?php
    // SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
    // $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
    // $PASSWORD - variable that contains your Salesforce.com password

    define("SOAP_CLIENT_BASEDIR", "../../soapclient");
    require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
    require_once ('../userAuth.php');

    try {
      $mySforceConnection = new SforcePartnerClient();
      $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
      $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

    /*--------------------------------------------------------\
    | Please manage the values for OBJECT ID from file 
    | userAuth.php
    \--------------------------------------------------------*/

      $fieldsToUpdate = array (
      'FirstName' => 'testupdate',
      'City' => 'testupdateCity',
      'Country' => 'US'
      );
      $sObject1 = new SObject();
      $sObject1->fields = $fieldsToUpdate;
      $sObject1->type = 'Lead';
      $sObject1->Id = $UPDATEOBJECTID1;

      $fieldsToUpdate = array (
      'FirstName' => 'testupdate',
      'City' => 'testupdate',
      'State' => 'testupdate',
      'Country' => 'US'
      );
      $sObject2 = new SObject();
      $sObject2->fields = $fieldsToUpdate;
      $sObject2->type = 'Lead';
      $sObject2->Id = $UPDATEOBJECTID2;
      $sObject2->fieldsToNull = array('Fax', 'Email');

      $response = $mySforceConnection->update(array ($sObject1, $sObject2));

      print_r($response);

    } catch (Exception $e) {
      print_r($mySforceConnection->getLastRequest());
      echo $e->faultstring;
    }
?>

else for enterprises wsdl use

<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.com password

define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforceEnterpriseClient.php');
require_once ('../userAuth.php');

try {
  $mySforceConnection = new SforceEnterpriseClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/enterprise.wsdl.xml');
  $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

/*--------------------------------------------------------\
| Please manage the values for OBJECT ID from file 
| userAuth.php
\--------------------------------------------------------*/

  $sObject1 = new stdclass();
  $sObject1->Id = $UPDATEOBJECTID1;
  $sObject1->FirstName = 'testupdate';
  $sObject1->City = 'testupdateCity';
  $sObject1->Country = 'US';

  $sObject2 = new stdclass();
  $sObject2->Id = $UPDATEOBJECTID2;
  $sObject2->FirstName = 'testupdate';
  $sObject2->City = 'testupdate';
  $sObject2->State = 'testupdate';
  $sObject2->Country = 'US';
  $sObject2->fieldsToNull = array('Fax', 'Email');

  $response = $mySforceConnection->update(array ($sObject1, $sObject2), 'Lead');

  print_r($response);

} catch (Exception $e) {
  print_r($mySforceConnection->getLastRequest());
  echo $e->faultstring;
}
?>
-1
source

All Articles