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

发布于 2024-12-22 07:44:56 字数 1692 浏览 2 评论 0原文

我搜索了几天,没有找到如何将自定义字段放入标准 SalesForce 对象(帐户、潜在客户、机会等...)。 我只找到此处描述的有关元数据 API 的信息,但它解释了仅在自定义对象上插入新元数据。我也找到了此代码,但它也仅适用于自定义对象。有人对这件事了解更多吗?谢谢。

编辑: 对于那些找不到示例的人来说,这是最终的工作代码。

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

I searched a couple of days and didn't find how can i put my custom fields in standard SalesForce object (Account, Lead, Opportunity etc...).
I found only info about metadata API described here, but it explains inserting new metadata only on custom objets. I found this code too, but it works only for custom objects too. Does anybody knows more about this stuff? Thanks.

EDIT:
Here is final working code for those who can't find example.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情感失落者 2024-12-29 07:44:56

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

You would create populate a CustomField structure, setting the fullName property based on the standard object you want to add it to, e.g. Account.rating__c and then pass that to the create metadata API call. I don't know about PHP, bu there's an example in .NET here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文