【发布时间】:2014-02-19 13:42:59
【问题描述】:
我想将一个外部 id 字段添加到一个还没有它的对象。
我需要什么:
- 连接到销售团队。
- 获取可用对象。
- 获取每个对象的字段。
- 检查其中一个字段是否是每个对象的外部 ID。
我需要它做什么:
- 如果外部 id 字段不存在:为此对象创建它。
- 在我的进程(迁移进程)结束时删除它的另一种方法。
以下代码用于连接到 salesforce org:
ConnectorConfig PartnerCfg = new ConnectorConfig();
PartnerCfg.setUsername(USERNAME);
PartnerCfg.setPassword(PASSWORD);
try {
myConnection = com.sforce.soap.partner.Connector.newConnection(PartnerCfg);
} catch (ConnectionException e) {
System.out.println("An error occured while connecting to the org.");
}
假设“Fields”是每个对象的字段数组,EXT_ID__C 是包含“Ext_Id__c”字符串的常量。
这是我目前编写的代码:
customFieldExists = false;
for (int j = 0; j < fields.length; j++) {
Field field = fields[j];
if ("customField__c".equals(field.getName())) {
customFieldExists = true;
}
// If field is the last of the object
if (j == fields.length - 1) {
if (customFieldExists == false) {
CustomField customField = new CustomField();
customField.setFullName(EXT_ID__C);
customField.setLabel("Ext_Id");
customField.setType(FieldType.Text);
customField.setExternalId(true);
customField.setLength(18);
// Here Should come the code to upload the field and its properties
// To salesforce org current object.
System.out.println("Created customField__c field in object " + ObjectName);
}
}
}
如何将 extId 自定义字段推送到我的组织?
【问题讨论】:
标签: java salesforce field