Saturday, February 23, 2013

Apex Classes used in Visualforce Controllers

StandardController Class  Vs StandardSetController Class

StandardController Class:

  • StandardController objects reference the pre-built visualforce controllers provided by salesforce.com
  • Only time it is necessary to refer standardcontroller object when defining the extension for standardcontroller.
  • Apexpages.standardcontroller sc=new ApexPages.StandardController(sobject);
StandardSetController Class:
  • StandardSetController objects allows to create list controllers similar to or extensions of the pre-built visualforce list controllers provided by salesforce.com.It also contains prototype object.
  • Prototype object is single sobject contained within the visuforce standardsetcontroller class.
  • If prototype object fields are set ,those values are used save action.
For List of Sobjects:
List<account> ls=[select id,name from account limit 5];
ApexPages.StandardSetController ssc=new ApexPages.StandardSetController(ls);

For QueryLocator:
ApexPages.StandardSetController ssc=new ApexPages.StandardSetController(Database.getQueryLocator([Select id,name from Account Limit 5]));

Action Class:
  • Use ApexPages.Action class to create an action method that you can use in visualforce controller or extension controller.
  • ApexPages.Action saveaction=new ApexPages.Action('{!save}');
Message Class:
  • When using Standard Controller,all validation errors,both  standard and custom that occur when end user saves the page are automatically added to the page error collection.
  • If you use Custom Controller or extension,you must use the message class to collecting errors.
  • ApexPages.message mss=new ApexPages.message(ApexPages.Severity,summary);
PageReference Class:
  • PageReference is a reference to instantiation of a page.
  • PageReference consists of URL and a set of query parameter  names,values.
  • By using PageReference Object,To view or set the query string parameters and values of page.
  • Also used ,to navigate the user to different page as  the result of an action method.

0 comments:

Post a Comment