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
Chamil MadusankaChamil Madusanka 

Create custom fields in apex code

Hi all,

 

Is there any possibility to create (dynamically create) custom fields in apex code?In that case we have to access schema. isn't it? How can i do this?

 

Thanks in Advance

sfdcfoxsfdcfox

You can theoretically create new fields using the CRUD-based Metadata API calls, but as this API is asynchronous, you may not be able to detect if the fields were successfully created in the same run as the attempt to create the fields. If you are using Visualforce to present the UI for this Apex Code, you could have the page call a function in the Apex Code that could check for the asynchronous results until a given timeout period. If you try this any other way (for example, from a trigger), then you would not be able to detect the success of your attempts at all. There is no technological reason why you could not create fields on the fly using Visualforce, but using pure Apex Code without Visualforce would be difficult, if not impossible, to use accurately.

Sridhar BonagiriSridhar Bonagiri

HI,

 

You can create new fields dynamically through apex code.

 

Sridhar Bonagiri

Red2678Red2678

Hi, are there any examples of this?