Visualforce Enlightenment


Occasionally I am asked to explain Visualforce to potential customers. “A set of pre-baked UI elements that allows you to quickly and easily expose and interact with your Salesforce data.” Sure.

That may get you through a sales pitch or scoping call, but if you are developing on the platform you would do yourself (and whoever you are working for) a favor to really understand Visualforce.

Not simply, how do you use it (there are lots of docs on this, not always complete but usually sufficient), but what is it? How does it work? Where would you use it ideally? Where not? What would you want to do if you wanted to extend it? Replace it?

The first thing to understand is that Visualforce is largely a port of Ajax for Java (a4j) / Java Server Faces (JSF), and there are sometimes bugs that are a part of those libraries that have made their happy way over to Visualforce. If you encounter a bug like this, you can search for “a4j” and the name of the element and you will frequently find additional workarounds.

The fact that there are painful bugs that hamper serious development on the platform can also be explained by this. The fact that nested apex:repeats, params without a name, and inconsistent behavior between commandbutton/commandlinks continue to cause frequent issues is very sad but perhaps inevitable since there is no one (as far as I know) tasked to handle these issues. If you are waiting and expecting these bugs to be fixed, don’t.

Second, the methods work as follows. Two sets of javascript are embedded in each element. The first is the default UI functionality of EXT.JS. It is feature complete in some sense, but lacks the fine-tuned user experience of alternatives like jQuery UI (and occasionally also features, like the limitations of the standard datepicker or the lack of any autocomplete). The second is the some attached javascript which handles form functions.

Each form in Visualforce land carries around its own copy of the entire viewState, which makes it likely a behemoth. Be very careful to declare your variables as transient whenever possible and not to put multiple copies of a form on a page if at all possible. Elements have nested crazy ids that are difficult to work with (but can be accessed via this method).

Review:

(1) Do use existing docs and community boards whenever possible.
(2) Don’t only use them, but also search google and a4j/jsf for solution
(3) Do extend Visualforce elements, either by creating your own components (see my jQuery UI set) (or very carefully, layering javascript on top of existing visualforce elements).
(4) Don’t muck with the underlying javascript.

If you are looking for a fuller treatment of the Force.com Platform, I suggest this longer post. Cheers!

One thought on “Visualforce Enlightenment

  1. agentgil says:

    What lies beneath visualforce – learn something new everyday

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: