function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vishal Gaddi6Vishal Gaddi6 

Crearing Custom fields using Apex code....

Hi Everyone

 

Can we create custom fields using apex code ?? if anybody have any code sample or link then do let me know....

 

 

 

Thanx in advance

Vishal

NiketNiket

Hi Vishal ,

 

I believe you can create custom fields by using metadata api in external application. However, according to me, through apex it is not possible.

Hpandey_ForceLabsHpandey_ForceLabs

 

Hello,

 

You cannot access the Metadata API through (via) Apex.  MetaData API is actually treated or intended to be used as Web Serivce API to be used for external clients 

 

On the other hand, you can't even callout web service API within the salesforce, just keep this in mind, you are always open to call external web service API.

 

Henceforth,  as of know, programmatically you cannot use the the Apex or some dynamic code to create custom fields. 

 

Anybody with suggestion/solution is highly welcome, if have any code bubbling in the think tank


Niket wrote:

Hi Vishal ,

 

I believe you can create custom fields by using metadata api in external application. However, according to me, through apex it is not possible.


 

Richa KRicha K

Hi Vishal,

I have tried this an year ago. As far as I know, we can't create custom field in Apex. But we can create custom objects and fields PROGRAMMATICALLY in Java and Dot Net. I tried upto this. As told by Hpandey_ForceLabs, we can't make callouts in Apex. It may sound some strange but if you can generate WSDL from Java and then from WSDL you can generate APEX. I dont know the end result though. :)

 

See this blog:

 

http://www.tgerm.com/2010/12/invoking-apex-wsdl-web-services-from.html

tes2tes2

You can use APEX to call the API and Metadata API by writing your own SOAP envelopes,  but to add a field requires both some xml maniplation and also requires the ability to unzip/zip your metadata package.  APEX can manipulate the xml but cannot handle binary manipulate so writing/converting custom unzip/zip classes are not possible.