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
vasu takasivasu takasi 

how to create a custom field from apex ..?


I want to create a custom field for OpportunityLineItem from apex.

How is it Possible?

Please can any one guide me.


Jeff MayJeff May

You can't create a new custom field from Apex.  That would require the Metadata API.  You can populate custom fields in Apex.

Tejpal KumawatTejpal Kumawat

Hi vasu,


Taking an example of add custom field "Address(Address__c)" of LongTextArea of 32768 character for OpportunityLineItem.


You can easily create Custom Field if you are using IDE or Eclipse by Putting below xml between <CustomObject> </CustomObject> tags of OpportunityLineItem.





Thanks & Regards



We can not create custom objects & custom fields from Apex. even we have some other option to create to create these meta Data from Eclipse using xml. 


Please give me KUDOS and mark it as solution if it was helpful

rajesh k 10rajesh k 10
Hi vasu takasi,
                          using  metadata api you create field any object in salesforce.find belo URL