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
ChethanChethan 

Can I create an Apex class in production organization with Rest API metadata service "/services/data/v27.0/sobjects/ApexClass/" ?

James LoghryJames Loghry
You can use the Tooling API (similar, but different to the metadata  API) to accomplish this.  For  more info see the Tooling API docs here: https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/.  Furthermore, this blog has a short tutorial on how to use the Tooling API to create an Apex class: https://www.sundoginteractive.com/blog/creating-classes-and-triggers-in-apex-using-the-tooling-api
ChethanChethan
Hello James,

Thank you for your reply, The blog link which you shared has a point saying "You cannot create a class or a trigger in a production environment" does this mean we cannot create classes in production environment using tooling api?

If not, How does Ant tool create classes/triggers in Production environment, Do you have any idea?

Thanks & Regards
-Tejas
James LoghryJames Loghry
The Ant tool utilizes the metadata api for deployments (as does the Force.com CLI and Eclipse plugin).  However, the metadata api is used for deploying classes and not creating them.  It's a subtle, but important difference.