+ Start a Discussion
Vasavi VajinepalliVasavi Vajinepalli 

URGENT: How to create custom objects and custom fields dynamically through Java or Apex


Can anyone please suggest me how to create custom objects and custom fields dynamically through Java or apex code.
If it is through Java, please suggest me the supported Jars as well. Appreciate if you can share the code for the same.

srlawr uksrlawr uk
If you really want to do this through code, you can engage the "Metadata API" to create objects and fields. You can do this via Java or Apex... though the approaches will be quite different. If you want to do it via Java you will have to overcome OAuth authentication etc. to access the APIs (standard oAuth library for that) if you develop a solution in Apex inside the Salesforce organisation you can just tap up the APIs straight off (I believe!)

So here is a link to the Metadata API create() function: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_create.htm

And there are examples here of how to use that to send the definition of a new object (using Apex):

You should be able to take that example and just fire an object into an Org if you want.. hopefully that will get you going? All you have to do then is copy and paste the code a bunch of times to insert the objects and fields you desire!
rajesh k 10rajesh k 10

You can do with metadata API.