function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Gyanendra Singh 8Gyanendra Singh 8 

Getter, Setter and Action methods

Below is the code taken from Visualforce Developer's guide:

VF Page-----------
<apex:page controller="myController" tabStyle="Account">
<apex:form>
<apex:pageBlock title="Congratulations {!$User.FirstName}">
You belong to Account Name: <apex:inputField value="{!account.name}"/>
<apex:commandButton action="{!save}" value="save"/>
</apex:pageBlock>
</apex:form>
</apex:page>

Controller class-----------------

public class MyController {
private final Account account;
public MyController() {
account = [SELECT Id, Name, Site FROM Account
WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}
public Account getAccount() {
return account;
}
public PageReference save() {
update account;
return null;
}
}

My question is how is the Update happening here When the save button is clicked?
What I understand is, account points to the account record whose id is specified in the URL and then if I enter some account name on <apex:inputField value="{!account.name}"/> how is the account being getting updated as the account still continues to point to the Account record whose Id is in URL but then how does it takes up the account name from inputField?

 
pconpcon
The class level variable account fetched during the constructor and then is passed to the VisualForce page by reference inside of getAccount.  The inputField then sets the Name variable on the class level account variable.  Then when the save method is called, all fields are "queried*" from the visual force page to get their current values. The updated account varaible is then updated in the database.  In this instance the only field that would be updated is the Name field since it is the only one made editiable on the VisualForce page.

* query isn't quite the right word, but it fits best.  It is more pulled from the state variable that is passed to the save method on the button click.
Gyanendra Singh 8Gyanendra Singh 8
Honestly I did not understand. Can you be more specific? 
pconpcon
This is not any simpiler, but it is mose specific.

https://developer.salesforce.com/page/An_Introduction_to_Visualforce_View_State

If you have any particular questions after reading this document, I can try to help.