GWT: Common Exceptions – NoClassDefFoundError

This seems to be a problem that nearly everyone hits when starting with GWT. It causes confusion because the code is error free at compile time, yet throws a java.lang.NoClassDefFoundError exception at runtime. The problem is simple to correct. You’ll probably have included the required library into your build path already and that’s why you’re not getting compile time errors. The additional step that is to have the JAR-file(s) that contain the required libraries be copied to your project’s war/WEB-INF/lib directory. Note that your JAR-files must exist in the root of this directory, and not in any sub-directories.

Salesforce Unit Tests & Code Coverage

Unit testing *sigh*. Oh how they vex me. If they weren’t so important (and required) I’d just skip the lot, but they are and so we – champions of software development – must press on in the face of dreary complexity; we will not back down, we will not surrender, we will look that CRT/LCD screen in the pixels and say, “Untested units, you will not defeat me!”.

Diving into the thick of things, the most common question seems to be, “Why can’t I get code coverage for my entire class?!”. The trick here is to think like a runtime engine, and consider how you might journey through all possible testing paths. Now I never said it’s easy, but with a bit of practice (and 8 truck loads of patience) you’ll get there. Let’s look at some common cases.

Read more

Salesforce Unit Tests & Code Coverage

Unit testing *sigh*. Oh how they vex me. If they weren’t so important (and required) I’d just skip the lot, but they are and so we – champions of software development – must press on in the face of dreary complexity; we will not back down, we will not surrender, we will look that CRT/LCD screen in the pixels and say, “Untested units, you will not defeat me!”.

Diving into the thick of things, the most common question seems to be, “Why can’t I get code coverage for my entire class?!”. The trick here is to think like a runtime engine, and consider how you might journey through all possible testing paths. Now I never said it’s easy, but with a bit of practice (and 8 truck loads of patience) you’ll get there. Let’s look at some common cases.

Read more

Handling System.QueryException

When attempting to fetch a single record from the database it is easy to run into the above exception. I’ve seen two schools of thought in dealing with this issue – mostly in the forums – and have been hoping to find a more official standpoint.

Read more

Throwing Custom Apex Exceptions

Throwing custom exceptions is something that most Java developers expect to be able to do when working with Apex code, and indeed it is possible. It isn’t very well documented, but I managed to stumble across this solution after some experimentation. Usually, I would expect an exception to be thrown using syntax at least similar to: However this syntax will give the follow error: Type cannot be constructed: Exception Instead you have to create a new exception class with extends the Apex Exception class: And then throw that new exception: That’s just the beginning of course, you could create some pretty fancypants error handling in your custom exceptions. The world is your oyster, now all your need is some Tabasco and lime.