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.


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

  • You are trying to create in Sandbox? I am sure you can create it, I did it using REST API. Nov 28, 2014 at 19:37
  • The Developer Console and the Force.com IDE uses the Tooling API, if I recall correctly, so I don't see why it shouldn't work in Java or any other language. Have you tried looking at the Force.com IDE source on GitHub?
    – sfdcfox
    Nov 28, 2014 at 19:40
  • @Jitendra Zaa I'm trying to create in Developer Edition. Yes, I've read on forums that REST API allows to do that. Nov 28, 2014 at 19:50
  • @sfdcfox I've tried looking at Eclipse Force.com IDE and they do that using Metadata API. I know that it works using Tooling API in Apex code. But in Java I can't do that Nov 28, 2014 at 19:51

1 Answer 1

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.

  • I would be very thankful to you if you tell me something about that (or give a link where I can get information about that) > Tooling API has some limitations (as well as advantages) Nov 28, 2014 at 23:20
  • Finally I've just done that ! It turned out that while testing how to use Tooling API I added apexClass.setFullName("TestSetFullName"); with wrong name. Nov 28, 2014 at 23:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .