Hi grace, we can add field from controller but i am not aware of from visuval force page.if you wannt to add field from apex then i can help you.you can refer this link for creating field from apex http://salesforce.stackexchange.com/questions/56421/create-custom-fields-with-apex
You can create custom fields to an object into a custom object by using metadata API
Please find the sample code snippet below. Please check with below link for more information.
- http://salesforce.stackexchange.com/questions/145777/is-it-possible-to-create-fields-using-apex-code
Please mark this as solved if the information helps.Best Regards,
Nagendra.
we can add field from controller but i am not aware of from visuval force page.if you wannt to add field from apex then i can help you.you can refer this link for creating field from apex
http://salesforce.stackexchange.com/questions/56421/create-custom-fields-with-apex
Hi Grace,
I've uploaded the code and a write up to Github, include pros and cons of this approach.
MetadataService.CustomObject customObject = new MetadataService.CustomObject();
customObject.fullName = 'Test__c';
customObject.label = 'Test';
customObject.pluralLabel = 'Tests';
customObject.nameField = new MetadataService.CustomField();
customObject.nameField.type_x = 'Text';
customObject.nameField.label = 'Test Record';
customObject.deploymentStatus = 'Deployed';
customObject.sharingModel = 'ReadWrite';
MetadataService.AsyncResult[] results = service.create(new List<MetadataService.Metadata> { customObject });
Enjoy!
https://github.com/financialforcedev/apex-mdapi