-
-
Save doppiomacchiatto/1f6d22af7a1c4f4b817e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class ViewStateStudy_controller { | |
public String accId{get;set;} | |
public Account account{get;set;} | |
public ViewStateStudy_controller() | |
{ | |
accId = ApexPages.currentPage().getParameters().get('Id'); | |
if(accId != null) | |
{ | |
this.account= [ SELECT Name | |
FROM Account | |
WHERE Id = : accId ]; | |
} | |
else | |
{ | |
this.account= new Account(); | |
} | |
} | |
public pageReference save() | |
{ | |
insert this.account; | |
return null; | |
} | |
public pageReference saveandclose() | |
{ | |
insert this.account; | |
//technically this works, but is not a best practice. | |
PageReference pageRef = new PageReference('/apex/test'); | |
pageRef.setRedirect(true); | |
return pageRef; | |
} | |
public PageReference page2(){ | |
return Page.ViewStateStudy_page2; | |
} | |
public PageReference page2byGet(){ | |
//this way will force initial page request by GET thus dumping view state | |
//usually this would be used to reset or cancel a set of page flows. | |
PageReference pageRef = Page.ViewStateStudy_page2; | |
pageRef.setRedirect(true); | |
return pageRef; | |
} | |
public PageReference page1(){ | |
return Page.ViewStateStudy_page1; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="ViewStateStudy_controller"> | |
<apex:form > | |
<apex:actionRegion > | |
<apex:pageBlock id="pbAccountDetails"> | |
<apex:pageBlockSection columns="1" collapsible="false"> | |
<apex:inputField value="{!account.Name}" required="true" /> | |
<!--<apex:inputfield value="{!account.Email__c}" required="true"/>--> | |
</apex:pageBlockSection> | |
<apex:pageBlockButtons > | |
<apex:commandButton action="{!save}" value="Save"/> | |
<apex:commandButton action="{!saveandclose}" value="Save and Close" immediate="true"/> | |
<apex:commandButton action="{!page2}" value="Next"/> | |
<apex:commandButton action="{!page2byGet}" value="Next by Get"/> | |
</apex:pageBlockButtons> | |
</apex:pageBlock> | |
</apex:actionRegion> | |
</apex:form> | |
</apex:page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page controller="ViewStateStudy_controller" > | |
<apex:form > | |
<apex:pageBlock > | |
<apex:pageBlockButtons > | |
<apex:commandButton action="{!page1}" value="Previous" /> | |
</apex:pageBlockButtons> | |
<apex:pageBlockSection > | |
<apex:outputField value="{!account.Name}"/> | |
</apex:pageBlockSection> | |
</apex:pageBlock> | |
</apex:form> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment