Apex and VF Basics
VisualForce:it is framework used for develop
sophisticated, custom user interface that can be natively hosted on force.com
platform.
Standard Controller:
Visualforce uses the MVC (Model View
Controller) architecture, and includes standard built-in controllers to provide the standard
actions functionality when user clicks on the buttons and links in visualforce
page These built-in controllers are referred to generally as standard
controllers, or even the standard controller.
Custom Controller:
As salesforce provides standard controllers
same way developers can write their own controllers to use one functionality
when user clicks on buttons and links on visualforce pages.It is Apex class
that implements all the logic of the visualforce page functionality(Not UI)
without leveraging a standard controller.
A developer can either use a standard
controller provided by the Force.com platform, or add extension
controller (to standard controller) or custom controller logic with
a class written in Apex.
Note:- Developer can use only one
controller and many extensions(with standard controller).
Steps To create a custom controller
Go to Setup -> Develop -> Apex Classes
Click on New button
e.g:test vf page and test controller
example.



Controller Methods:
·
Getter (Property of the class)
·
Setter (Property of the class)
·
Actions
What is
a property?
•
Similar
to a variable, however, can do additional things in code.
Getter
Methods
•
Getter
methods return values from a controller.
•
Getter
methods must always be named getVariable.
Setter
Methods
•
Setter
methods pass user-specified values from page markup to a controller.
•
Any
setter methods in a controller are automatically executed before any action
methods.
•
Setter
methods must always be named setVariable.
What is
an action method?
•
Action
methods perform logic or navigation when a page event occurs, such as when a
user clicks a button.
•
Help
to define certain tasks that should be carried out when the corresponding
button or link is clicked on a visualforce page.
•
Action
methods can be called from page markup by using {! } notation in the action
parameter.
•
One
of the main differences between an action method and a regular method is that
an action method should return an object of type PageReference upon
completion.
•
An
action method as returning nothing (void) can be defined, but that is
equivalent to returning a NULL PageReference object.
There are
following types of collections in Apex:
Lists
: Ordered collection of elements
Data type – Primitive, collections, sObjects,
User defined and built In apex types
Syntax
List<DataType> lst = new
List<DataType>();
List<DataType> lst = new string[5]
List Methods:
Add().
Remove().
Sort().
Sets: UnOrdered collection of elements
Do not contain duplicates
Syntax
Set<DataType> s1 = new
Set<DataType>();
Set<String> s1 = new
Set<String>{'a', 'b + c'};
Maps: Key-value pairs
Key are unique
Syntax
Map<DataType, DataType> State_code = new
Map<DataType, DataType>();
Map<String, Integer> State_Codes = new
Map<String, Integer>{'Maharashtra' => 1, 'Tamilnadu' => 2,’madhyapradesh’
=>3};
0 Comments