The company recently came upon the need to create a side by side record comparison in Visualforce / Apex. We routinely have the need to merge leads into contacts. Previously this was handled in S-Controls; however, recent initiatives and desire to have support for our code on into the future has pushed us to move many of our S-Controls into Visualforce pages and Apex code.
We are looking to achieve something like this:

I have experimented somewhat (with little luck) doing this using the apex:pageBlockTable tag; however, I am not sure how to get two sets of data to render through when it is expecting a single SObject.
All of the prior code I have to work with was done in S-Controls using JavaScript; and while this code does work now – we need to port this to a VisualForce page. Obviously I can manually write this using HTML tables…etc but I believe that defeats the purpose of using the stock Salesforce functionality.
I’m definitely open to alternative methods – as the one i have outlined works, but requires an almost painful amount of coding to make it viable (especially as fields are updated/removed/added in the future).
The answer ended up being very straight forward!
First – As it turns out, the
apex:pageBlockTablecan handle pretty much any kind of object passed into thevalueparameter, be it an array of SObjects or an array of MyFooBar objects.Second – we needed a wrapper class to encapsulate two records at the same time:
Third – We need to create a ‘compare’ class that holds two values and two booleans based on which value is selected (and a row label to display on the table):
Then it is as simple as putting it all on a VF page with the following:
Finally we just need a little javascript to make the radio buttons behave properly 🙂
The javascript can be placed pretty much anywhere on the page, but it’s best to either link it or place it at the top of the document just after the opening tag.
Once this has been done you can (from the code) access your
LeadContactCompareWrapper.[information|marking|furtherDetails]array and step through each one to determine the selected values, or write additional helper classes to expedite the process.With this in place we were able to create a side-by-side record comparison that allowed us to merge our leads directly into our contacts!