3

我一直在研究这一点,并根据我对如何更新 SObject 中的记录的理解尝试了许多变体,但我不断收到以下错误:

SoapFault 异常:[sf:INVALID_TYPE] INVALID_TYPE:必须发送一个具体的实体类型。在 /home/public_html/soapclient/SforceBaseClient.php:509

我能够成功登录到该页面,但是当我执行下面的代码时,我收到了上面列出的错误。

    $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;
    }

我正在使用 Force.com 开发人员文档中的 PHP Toolkit 13.0,但无法深入了解此错误。另外,我在沙盒模式下使用 Enterprise WSDL,并分配了正确的 wsdl xml。

谢谢。

4

3 回答 3

1

sObject 是可更新的所有其他 Salesforce 对象的基本类型。使用企业 API (SOAP) 时,您需要传递派生自 sObject 的实例。(Lead、Contact 和 Account 是示例)

这里也是update()方法的文档。

于 2012-04-26T15:25:02.227 回答
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');

仅供参考,我从来没有找到一次更新多个对象类型的方法,但是您可以更新一批相同类型的对象,因此第一个参数需要是一个数组。Salesforce 工具包不会自动考虑传递单个对象的人(即它不会为您将其包装在数组中)。我一直在我的应用程序逻辑和 Salesforce 的 SOAP 工具包之间使用一个抽象层,它提供了我刚才描述的便利。

于 2014-01-11T21:26:23.657 回答
0

如果您使用的是合作伙伴 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;
    }
?>

其他企业 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.'/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;
}
?>
于 2014-06-05T14:23:18.797 回答