【发布时间】:2016-03-15 13:40:26
【问题描述】:
我正在使用 Salesforce 和 force.com API 和元数据 API,版本 36。 我可以在 Lead 对象中创建自定义字段,但默认情况下我可以看到它是隐藏的,这意味着我无法使用这些自定义字段创建新的 Lead,因为它返回错误的请求(400 状态代码)。 有什么方法可以通过代码设置自定义字段可见吗?
public boolean createCustomExtTextField(String name, LoginResult metadataLoginResult, int length) {
boolean success = false;
CustomField cs = new CustomField();
cs.setFullName("Lead."+name+"__c");
cs.setLabel("Custom"+name+"Field");
cs.setType(FieldType.LongTextArea);
cs.setLength(length);
cs.setVisibleLines(50); // max 50
try {
MetadataConnection metadataConnection = createMetadataConnection(metadataLoginResult);
SaveResult[] results = metadataConnection.createMetadata(new Metadata[] { cs });
for (SaveResult r : results) {
if (r.isSuccess()) {
success = true;
} else {
System.out.println("Errors were encountered while creating " + r.getFullName());
for (com.sforce.soap.metadata.Error e : r.getErrors()) {
System.out.println("Error message: " + e.getMessage());
System.out.println("Status code: " + e.getStatusCode());
}
}
}
} catch (ConnectionException e) {
e.printStackTrace();
}
return success;
}
我在谷歌上搜索了很多,但没有找到真正有用的东西。因此,欢迎任何提示。谢谢。
【问题讨论】:
-
不确定这是否与这篇文章有关:developer.salesforce.com/forums/?id=906F0000000AY54IAG。我不想更改整个配置文件,只想更改 Salesforce 对象中自定义字段的可见性。
标签: salesforce apex-code