Simon Fell > Its just code > ApexCoder

Wednesday, June 20, 2007

The Apex Code developer preview is going strong and I'd guess everyone is using the Eclipse plug-in to author their apex code packages and triggers. What you may not know, is that the plug does its work over the web services API, and if you look in the WSDL page in the Salesforce.com app, you'll see there's an extra WSDL called Apex WSDL, and this contains the operations to compile packages and triggers, run the unit tests, and execute anonymous blocks of apex code. So, if the eclipse plug-in doesn't float your boat, well, heck build your own. (This WSDL is part of the developer preview, so its definition and availability is still subject to change, but if you have an opinion, let us know).

I built a simple OSX command line tool called ApexCoder that uses this API to upload & compile apex code, its pretty easy to use, e.g.

# compile the package contained in the file tm.apex, read my username and password from the keychain.
./apexCoder -kc package tm.apex

# same as above, but with explicit username and password
./apexCoder foo@bar.com somePassword package tm.apex

# compile these 3 packages in one go
./apexCoder -kc package tm.apex accounts.apex quote.apex

# compile these 2 triggers
./apexCoder -kc trigger accounts.apex contacts.apex

# execute the block of apex code in anon.apex directly (execute Anonymous)
./apexCoder -kc execAnon anon.apex

# run the tests in these packages
./apexCoder -kc runTests accounts contacts

# store my credentials on the keychain (for later use with the -kc option)
./apexCoder foo@bar.com somePassword setkc

Of course, no one wants to mess around with command line tools directly, so being a big TextMate fan, I also put together a TextMate bundle so you can do all this directly from TextMate. (unzip the file, drop it in ~/Library/Application Support/TextMate/Bundles). The bundle requires you to use the keychain option, so the first thing you'll want to is goto Salesforce.com in the bundle menu and pick 'Set Login Credentials'. Once you've done that, the other options in there will all work. For compile package, compile trigger and execute anonymous these all operate on the current file. for runTests, select the package name in your source code and select run tests. The bundle includes a still rudimentary apex language grammar, so you get some syntax highlighting, although its far from finished. There's also probably a bunch of good templates and snippets that could be added as well.