5

I need to save some Apex classes through API in java and this question confused me:

In documentation for the Tooling API I found an example how to update Apex class using MetadataContainer. This example includes a lot of lines of code and about three API calls to server.

Then I found out that I can easily update an apex class using compileClasses or compileAndTest call in Apex API. And this way is much more comfortable for me for many reasons:

1) I need only one API call

2) There is much fewer code

3) I DON'T need to know an Id of an Apex class

4) With this call I can send many classes without knowing if they already exist or not, and everything will be done well : new classes will be created and existing classes will be updated.

So is there any reason why I should use Tooling API and MetadataContainer for that purpose instead of using Apex API and compileClasses?

And by the way - the same question about create call in Soap API. Can I just always use Apex API for all this purposes?

Or there are some details which I don't know/understand or any side effects in using Apex API for such purposes?

I'm using developer edition. Is it possible that in production edition or in sandbox it will work other way?

2

I'd say go with the Tooling API over the Apex API. The Apex API isn't really getting updates any more and has largely been replaced by the Tooling API. Long term you will have more options using the Tooling API.

That said, the Apex API should remain functional and is a valid option if you want to keep your API calls to a minimum and don't know if the classes exist or not.

If you have a new ApexClass you can do one call to the Tooling API create method. If your have one or more existing Apex classes use the MetadataContainter to update them all in one go. Yes it is 3 calls to create the MetadataContainer, then the ApexClassMembers, and then the ContainerAsyncRequest.

With the Apex API you would need to use compileAndTest() against a production environment rather than compileClasses().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.