Tuesday 3 May 2011

Wrapper Class in Apex/Visual force page


Wrapper class is a very powerful concept that can be used in multiple scenarios. Putting aside the word "Wrapper" it is nothing but just a class.Just like what we have in a class ,we  have methods,Properties etc in a wrapper class too.Here is an use case for wrapper class

Requirement : A Visual force page has to display all the Contacts available for an Account .Contacts should be listed out in the table row wise(default being column wise) . Only created "date"(Strip the time part) of the contact should be displayed .

Sample page:









Apex Code :



Visual force page :


Result :












Huh!! now please don't catch a bug here that no values are displayed for phone. I admit i missed them..Pretty tired ...accept my apology and take it for granted :) :)

Power of wrapper is seamless .It can be used to process only the records that are selected in vf page.Click on the link for example.

http://wiki.developerforce.com/index.php/Wrapper_Class

Happy Coding!
C ya Soon with another Post

4 comments: