As a developer, I’m often times very eager to jump in and start writing code. The Salesforce platform however has a “Clicks Not Code” methodology that I often overlook. Much of the time when a developer is asked to step in, the majority of the “Clicks Not Code” options have been exhausted. It’s no wonder then that I often forget that even though its time to start slinging code, there are number of prebuilt items that I can leverage. This morning, this bit me in the posterior for awhile.
I was working with a bit of legacy code that now required us to have different types of the same object, we’ll call this Object A for simplicity sake. We also have another custom object, Object B that has a lookup to Object A. However, Object B now also needed two more lookups to Object A in order to represent the other types (it was possible to have all three populated at the same time). So far so good. Object B -> Lookup Object A (Type 1), Object B -> Lookup Object A (Type 2), Object B -> Lookup Object A (Type 3).
Object A is represented in the UI using a custom VF page. Now normally, I’d be all to eager to build the VF page *completely* from scratch, field by field as that’s what I’ve been doing for 14 years. With Salesforce, its possible to leverage the prebuilt pieces of the object PageLayout using specific apex tags. In this case, the existing page was using <apex:detail> and <apex:relatedList/> tags to represent the basic details of the object and the Object B related list respectively. I had to add two more related lists to this page and have them conditionally rendered based on Object A’s type field.
The original Object B related list had several columns that my related list needed to duplicate, however no matter what I did I could not figure out how to add these columns to my related lists. As it turns out, the answer is simple. Since I was using the <apex:relatedList/> tag, all I had to do was edit Object A’s standard page layout, select my related lists, and add the columns there. This thought never even occurred to me because after all, from a coding stand point, I was using VisualForce, not the standard page layout, all the while forgetting that the builtin in tags use the default related list functionality from the page layout.
So, if you find yourself struggling in VisualForce code, don’t forget some of the black box magic that is taking place behind the scenes. Even though you may not be using the standard page layout, that standard functionality is still playing a role.