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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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!
Method 2
I’m using SAP PO 7.4 as a middleware to integrate with Salesforce. Problem i’m facing is ? The Enterprise WSDL doesn’t shows all actual fields information for doing mapping.
So, can we create custom fields and post to the salesforce by using update/upsert methods ?
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0