Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I am using the SOAP API to load data for multiple SObject types into a completely new Developer sandbox.

I have manually added external ids to many of the objects through the native interface so that I can use them to create relationships when loading my records.

However, I would like to create these external ids through code at the start of my program, but am not sure of the best way of doing this. If I create a new field via an API, then that field won't be in the WSDL that I have downloaded, so I won't be able to use methods such as `account.setAccExtId__c()' without updating the WSDL, but this is what I want to do.

  • Is there a way of adding a field via an API and then immediately being able to use getters and setter for that field in my Java code?
  • Can we only add a field via the MetaData API? I have been using the SOAP API for uploading and deleting records.

Thanks

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

Good question!

  • You can indeed use the Metadata API create operation to create fields, by passing it the CustomField data type. You can see some examples of using this operation here, although they are Apex code examples the process is the same.
  • It sounds from your description that you are using the Enterprise WSDL, you need to switch to the Partner WSDL for your use case. So that you can dynamically determine and send the fields you have created.

The following is from the Salesforce docs relating to the Enterprise WSDL...

Note the following when generating the enterprise WSDL: If new custom fields or objects are added to, renamed, or removed from your organization’s information, you need to regenerate the WSDL file in order to access them. The generated WSDL contains the objects and fields in your organization, including those available in the selected versions of each installed package.

The following describes the Partner WSDL...

This API is for salesforce.com partners who are developing client applications for multiple organizations. As a loosely-typed representation of the Salesforce object model, the partner WSDL can be used to access data within any organization.

So while the Partner WSDL may not be as friendly to use, it is better for more dynamic use cases such as yours.

Hope this helps!

share|improve this answer
    
Good answer! Thanks –  Joe Jan 22 '13 at 13:25
    
Your welcome Joe, if it works out please feel free to accept it as a valid one. :-) –  Andrew Fawcett Jan 22 '13 at 13:33
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.