从 Flex (Salesforce) 创建自定义字段
我正在尝试从 Flex 创建自定义字段,但我很难找到正确的语法。
下面是我正在使用的代码片段,它导致错误“sf:INVALID_TYPE INVALID_TYPE:创建/更新请求中不允许空对象”
var con:Connection = new Connection();
var lRequest:LoginRequest = new LoginRequest();
lRequest.username = username1.text;
lRequest.password = password1.text;
lRequest.callback = new mx.rpc.Responder(createFields, loginFault);
con.login(lRequest);
//CreateFields Method ....
var externalIdField:CustomField = new CustomField();
externalIdField.label = 'ProductionId';
externalIdField.type = FieldType.ID;
externalIdField._length = 18;
externalIdField.externalId = true;
externalIdField.unique = true;
var customObjectVar:CustomObject = new CustomObject();
customObjectVar["type"] = "Account";
customObjectVar.addField(externalIdField);
var objarray:Array = [];
objarray[0]=customObjectVar;
con.updateObject(objarray,new mx.rpc.Responder(saveresults,sfdcFailure));
尝试了以下替代方法(按照西蒙的建议),这也会导致错误
“soapenv:客户端元素 {http://soap.sforce.com/2006/04/metadata}类型 在此位置无效”
var externalIdField:CustomField = new CustomField();
externalIdField.fullName = 'Account.ProductionId__c';
externalIdField.type = FieldType.STRING;
externalIdField._length = 18;
externalIdField.externalId = true;
externalIdField.unique = true;
var objarray:Array = [];
objarray[0]=externalIdField;
con.updateObject(objarray,new mx.rpc.Responder(saveresults,sfdcFailure));
`
I'm trying to CREATE custom fields from flex, but I'm having hard time finding the correct syntax.
Below is the piece of code that I'm using and it's resulting in error "sf:INVALID_TYPE INVALID_TYPE: null objects not allowed in create/update request"
var con:Connection = new Connection();
var lRequest:LoginRequest = new LoginRequest();
lRequest.username = username1.text;
lRequest.password = password1.text;
lRequest.callback = new mx.rpc.Responder(createFields, loginFault);
con.login(lRequest);
//CreateFields Method ....
var externalIdField:CustomField = new CustomField();
externalIdField.label = 'ProductionId';
externalIdField.type = FieldType.ID;
externalIdField._length = 18;
externalIdField.externalId = true;
externalIdField.unique = true;
var customObjectVar:CustomObject = new CustomObject();
customObjectVar["type"] = "Account";
customObjectVar.addField(externalIdField);
var objarray:Array = [];
objarray[0]=customObjectVar;
con.updateObject(objarray,new mx.rpc.Responder(saveresults,sfdcFailure));
Tried below alternate way (as suggested by Simon), that too results in error
"soapenv:Client Element
{http://soap.sforce.com/2006/04/metadata}type
invalid at this location"
var externalIdField:CustomField = new CustomField();
externalIdField.fullName = 'Account.ProductionId__c';
externalIdField.type = FieldType.STRING;
externalIdField._length = 18;
externalIdField.externalId = true;
externalIdField.unique = true;
var objarray:Array = [];
objarray[0]=externalIdField;
con.updateObject(objarray,new mx.rpc.Responder(saveresults,sfdcFailure));
`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要创建字段,您需要将 CustomField 实例传递给元数据 api create 调用(从您的代码中不清楚
con
是什么),除了您设置的字段之外,您还需要设置 fullName (例如本例中的 Account.ProductionId__c )To create fields you would pass a CustomField instance to the metadata api create call (its not clear from your code what
con
is), in addition to the fields you've set, you need to set the fullName (e.g. Account.ProductionId__c in this case)