[SalesForce] save a new Apex class using Tooling API in java

Is it possible to create a new Apex class using Tooling SOAP API in java?

When I'm trying to do that I get

ApiFault exceptionCode=’INVALID_TYPE’
exceptionMessage=’This type of object is not available for this organization'” 

I was looking for the answer for that question and according to what I saw on forums it seemed that answer is "not possible".

But documentation says

These examples use Java, but you can use Tooling SOAP API in any
language that supports Web services. Use create() to compile Apex
classes or triggers in Developer Edition or sandbox organizations.

I would like to hear the last word just to be absolutely sure. Maybe someone has managed to create an Apex class in JAVA through Tooling SOAP API or someone knows absotively that it's NOT possible.

UPDATE

Yes, it is POSSIBLE .

While I was exploring Tooling API I added apexClasssetFullName("TestSetFullName"); for some reason (now I can't even remember why did I do that) with WRONG CLASS NAME. It didn't work because of that stupid mistake

Best Answer

Can I save a new Apex class using Tooling API in java?

For Sandbox and Dev Orgs the answer is Yes, using both SOAP and REST flavours of Tooling API.
Example here is written in scala, but in java it would not be much different. Both use JVM any way. The create() class bit is lines 66-74.
Whether it is a good idea or not (to use Tooling over Metadata API) depends on your use case. Tooling API has some limitations (as well as advantages) compared to Metadata API and may not be suitable in some cases.

SFDC SOAP (and REST) web services do not care which languages their clients use.
Example of create() call on this page of current version (v32) of Tooling API documentation claims to be in Java, but in reality it looks suspiciously like .NET. Either way in Java this example would look very much the same.

Related Topic