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
ssoftwaressoftware 

adding custom field to a standard sobject via Apex

Hi All,

 

Is it possible to add a custom field to a standard SObject (Account etc..) via Apex? If it is, can someone point me in the right direction or show me some sample code?

 

Thanks in advance!

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

If you are talking about defining a new field on the object, then I'm afraid you can't do that - you'd need to use the metadata API which isn't available in Apex.

All Answers

bob_buzzardbob_buzzard

If you are talking about defining a new field on the object, then I'm afraid you can't do that - you'd need to use the metadata API which isn't available in Apex.

This was selected as the best answer
ssoftwaressoftware

Thanks Bob. I will look into the metadata API.