编程语言
首页 > 编程语言> > 如何使用元数据API使用PHP将自定义字段放在Standard SalesForce对象上

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

作者:互联网

我搜索了几天,却找不到如何将自定义字段放入标准SalesForce对象(帐户,销售线索,商机等)中.
 我仅找到有关描述here的元数据API的信息,但它说明了仅在自定义objets上插入新的元数据.我也找到了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;
}

解决方法:

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

标签:custom-fields,metadata,php,salesforce
来源: https://codeday.me/bug/20191202/2084710.html