如何使用元数据API将自定义字段放在Standard SalesForce对象上,使用PHP

时间:2011-12-20 20:42:17

标签: php metadata salesforce custom-fields

我搜索了几天,但没有找到如何将我的自定义字段放在标准的SalesForce对象(帐户,潜在客户,机会等...)中。  我只找到了有关描述here的元数据API的信息,但它解释了仅在自定义对象上插入新元数据。我也发现了this code,但它也适用于自定义对象。有人知道更多关于这个东西吗?感谢。

修改 以下是那些找不到示例的人的最终工作代码。

// 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 (SOAP_CLIENT_BASEDIR.'/SforceMetadataClient.php');
require_once ('../userAuth.php');
try {
  $mySforceConnection = new SforcePartnerClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
  $loginResult = $mySforceConnection->login($USERNAME, $PASSWORD);
  $myMetadataConnection = new SforceMetadataClient(SOAP_CLIENT_BASEDIR.'/metadata.wsdl.xml', $loginResult, $mySforceConnection);
  $customField = new SforceCustomField();
  $customField->setFullName('Account.MyCustomFieldb__c');
  $customField->setDescription('Description of New Field');
  $customField->setLabel('My Custom Field Label');
  $customField->setType('Text');
  $customField->setLength(255);
  print_r($myMetadataConnection->create($customField));
} catch (Exception $e) {
  echo $myMetadataConnection->getLastRequest();
  echo $e->faultstring;
}

1 个答案:

答案 0 :(得分:3)

您将创建填充CustomField结构,根据要添加到其中的标准对象设置fullName属性,例如: Account.rating__c然后将其传递给create元数据API调用。我不知道PHP,在.NET here中有一个例子。