I have taken a reference from : https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_custom.htm and developed below code.
But it gives me the following error.
FATAL_ERROR System.QueryException: List has no rows for assignment to SObject
MyController
public class MyController {
private final Account account;
public MyController(){
Id newId = ApexPages.currentPage().getParameters().get('id');
System.debug('New ID : '+newId);
account = [SELECT Id, Name, Site FROM Account WHERE Id = :newId];
}
public Account getAccount(){
return account;
}
public PageReference save(){
update account;
return null;
}
}
MyControllerVF
<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>
My input screen.
?id=<an account id>
in the url when requesting the page.