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
Jake GmerekJake Gmerek 

Dynamic Field Creation

Can you Dynamically create a field in a Trigger?

 

something like mySobject.addField(name = 'myName', etc);

 

I don't think that you can do that, but I thought I would ask before I gave up.

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Cory CowgillCory Cowgill

You can use the Metadata API to create objects / fields.

 

http://www.salesforce.com/us/developer/docs/api_meta/index.htm

 

If you want to perform this in the context of a trigger (which is kinda crazy use case for most situation, and I'd advise against it if possible), you'll need to use a @future method since the metadata api is a Web Service.

 

 

All Answers

CLKCLK
I dont thing any API given by force.com to create field; so It may be impossible from anywhere not just trigger
Cory CowgillCory Cowgill

You can use the Metadata API to create objects / fields.

 

http://www.salesforce.com/us/developer/docs/api_meta/index.htm

 

If you want to perform this in the context of a trigger (which is kinda crazy use case for most situation, and I'd advise against it if possible), you'll need to use a @future method since the metadata api is a Web Service.

 

 

This was selected as the best answer
Jake GmerekJake Gmerek

Thanks!

CLKCLK
Hi Cory, Sorry for putting inifficient info on board, but i am unable to findout API which create field/object. Could you please give me that piece of code/name of API which actually create field/object using metadata API wsdl.