Winter ’12 Developer Console

I didn’t take much notice of the Winter ’12 Platform Release Developer Console as there was no mention of that important word “breakpoint”. But if you are in debug hell then the features that are provided to allow debugging without having to add System.debug calls – including the ability to capture and view the heap at points marked in your source code – are worth investigating.

This (hour long) presentation demonstrates how to use the features:

It also suggests that the Eclipse tooling (and 3rd party additions to that tooling) will eventually be able to use the same API. I find the current browser-based console fragile (using Chrome) and a bit awkward to use as it packs a lot of tabs and frames into a small space; hopefully the richer UI facilities in Eclipse will help. But worse, on the sort of pages and code that require debugging, i.e. non-trivial larger ones, the volumes of data that the tooling attempts to move from server to client are so large that the time delays make the tooling barely usable at all.

Note that while this tooling can be used as you develop your managed package, when that managed package is installed in a customer’s org all the code-related debug information is unavailable (by default but can be turned back on via a support request) so the ability to debug is also lost.

Referencing static resources where the name is not known at compile time

PS Note that the Dynamic References to Global Variables feature in Spring ’12 addresses this problem.

If you have a static resource such as an image that you want to display in a page there is a well documented method of referencing that static resource – see e.g. Delivering Static Resources with Visualforce. If the static resource is named “MyResource”, that resource is referenced using “$Resource.MyResource”. But this relies on the name being known at Visualforce page compilation time and the compilation also verifies that the static resource exists. If you want to provide the static resource name dynamically from a controller property there appears to be no way to do it. (In my case I wanted the name of a customer-specific ZIP file containing a help system to be configurable via a custom setting.)

By inspection (and as described in the above link), “$Resource.MyResource” results in a reference in the HTML of the form “/resource/1319816508000/MyResource”. With a bit of rooting around, that observation leads to this code:

public String myResource {
    get {
        String namespace = null;        
        String name = 'MyResource';
        StaticResource sr = [
                select LastModifiedDate
                from StaticResource
                where NamespacePrefix = :namespace
                and Name = :name
                limit 1
        return '/resource/' + sr.LastModifiedDate.getTime() + '/' + (namespace != null ? namespace + '__' : '') + name;

which so far has worked for me.