You need to sign in to do that
Don't have an account?

Dynamically add new field to a sObject
Hi all;
Is there a way to create a new field in a sObject by using Apex code.
For an example I want to create a field named "OpportunityNumber" at run time.
I want something similar to following code.
Opportunity.createNewField('OpportunityNumber');
As far as I know you can't create a field from apex code.
One possible aproach is to have a service on an external server that is called from whitin apex. this service calls salesforce using the Metadata API and creates the records you need at run time. This is not "THE" perfect solution for your case because you need a server and code programmed in another platform (like php,c#, java) but is doable and the code needed is pretty simple.
Thanks Farid.