使用Salesforce CRUD Metadata API创建自定义对象时出现异常

时间:2012-08-20 19:52:39

标签: java api wsdl salesforce crm

当我尝试使用CRUD Matadata API在Salesforce中创建自定义对象时,我收到以下异常。

     com.sforce.ws.SoapFaultException: Must specify a {http://www.w3.org/2001/XMLSchema-instance}
 type attribute value for the {http://soap.sforce.com/2006/04/metadata}metadata element
        at com.sforce.ws.transport.SoapConnection.createException(SoapConnection.java:205)
        at com.sforce.ws.transport.SoapConnection.receive(SoapConnection.java:149)
        at com.sforce.ws.transport.SoapConnection.send(SoapConnection.java:98)
        at com.sforce.soap.metadata.MetadataConnection.create(MetadataConnection.java:273)
        at com.sfo.service.SalesforceObjectBootstrap.createCustomObject(SalesforceObjectBootstrap.java:226)

我正在使用此链接中的代码,我更改的唯一内容是自定义对象的名称 http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_calls_intro.htm

此步骤发生异常

AsyncResult[] asyncResults = metadataConnection.create(new CustomObject[]{customObject});

在调用上面的create方法之前的Custom对象具有以下参数值。

[CustomObject [Metadata  fullName='lead_5273_custom_reg__c'
]
 actionOverrides='{[0]}'
 articleTypeChannelDisplay='null'
 businessProcesses='{[0]}'
 customHelp='hey there help me'
 customHelpPage='null'
 customSettingsType='null'
 customSettingsVisibility='null'
 deploymentStatus='Deployed'
 deprecated='false'
 description='Created from backend Webcast API : Lead 5273 Custom Reg'
 enableActivities='false'
 enableDivisions='false'
 enableEnhancedLookup='false'
 enableFeeds='false'
 enableHistory='false'
 enableReports='false'
 fieldSets='{[0]}'
 fields='{[0]}'
 gender='null'
 household='false'
 label='Lead 5273 Custom Reg'
 listViews='{[0]}'
 nameField='[CustomField [Metadata  fullName='lead_5273_custom_reg__c'
]
 caseSensitive='false'
 customDataType='null'
 defaultValue='null'
 deleteConstraint='null'
 deprecated='false'
 description='field name for a metadata custom object'
 displayFormat='null'
 escapeMarkup='false'
 externalDeveloperName='null'
 externalId='false'
 formula='null'
 formulaTreatBlanksAs='null'
 inlineHelpText='null'
 label='Lead 5273 Custom Reg'
 length='0'
 maskChar='null'
 maskType='null'
 picklist='null'
 populateExistingRows='false'
 precision='0'
 referenceTo='null'
 relationshipLabel='null'
 relationshipName='null'
 relationshipOrder='0'
 reparentableMasterDetail='false'
 required='false'
 restrictedAdminField='false'
 scale='0'
 startingNumber='0'
 stripMarkup='false'
 summarizedField='null'
 summaryFilterItems='{[0]}'
 summaryForeignKey='null'
 summaryOperation='null'
 trackFeedHistory='false'
 trackHistory='false'
 type='Text'
 unique='false'
 visibleLines='0'
 writeRequiresMasterRead='false'
]
'
 namedFilters='{[0]}'
 pluralLabel='Lead 5273 Custom Regs'
 recordTypeTrackFeedHistory='false'
 recordTypeTrackHistory='false'
 recordTypes='{[0]}'
 searchLayouts='null'
 sharingModel='ReadWrite'
 sharingReasons='{[0]}'
 sharingRecalculations='{[0]}'
 startsWith='null'
 validationRules='{[0]}'
 webLinks='{[0]}'
]

我使用这里提到的方法来生成WSDL文件及其java骨架。 http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_quickstart.htm#topic-title-sample-code

我的代码与上面提供的示例完全匹配。我只是复制粘贴整个东西。

我找到了这个链接,它提到了同样的例外。但此链接与创建文件夹有关。 http://boards.developerforce.com/t5/Java-Development/Metadata-API-errors-Must-specify-a-type-attribute-value-for-the/td-p/175253

请让我知道如何解决这个问题。

1 个答案:

答案 0 :(得分:1)

我自己并没有玩过这个,但是从异常的外观来看,MetaData阻止了这里:

[CustomObject [Metadata  fullName='lead_5273_custom_reg__c']

需要包含对象类型,我假设在这种情况下是CustomObject__c(所有自定义对象都有__c后缀),所以可以尝试以下方法:

[CustomObject [Metadata  fullName='lead_5273_custom_reg__c' type='CustomObject__c']

除非当然,fullname实际上是对象名称,这可能是一种可能性。