<apex:page standardController="Product_Brief__c" sidebar="true" showHeader="true" extensions="SUM">
<apex:form >
<apex:pageBlock id="myPanel">
<apex:pageBlockSection title="Section 1: Custom Media Information" collapsible="false" >
<apex:outputField value="{!Product_Brief__c.Opportunity__r.Account.Name}" rendered="{!NOT(bEditMode)}" />
<apex:inputField value="{!Product_Brief__c.Customer_Number__c}" rendered="{!bEditMode}"/>
<apex:outputField value="{!Product_Brief__c.Customer_Number__c}" rendered="{!NOT(bEditMode)}" />
<apex:inputField value="{!Product_Brief__c.Billing_Address__c}" rendered="{!bEditMode}"/>
<apex:outputField value="{!Product_Brief__c.Billing_Address__c}" rendered="{!NOT(bEditMode)}" />
<apex:outputField value="{!Product_Brief__c.CreatedBy.Name}" Label="Contact Name" rendered="{!NOT(bEditMode)}" />
<apex:inputField value="{!Product_Brief__c.Shipping_Address__c}" rendered="{!bEditMode}"/>
<apex:outputField value="{!Product_Brief__c.Shipping_Address__c}" rendered="{!NOT(bEditMode)}" />
</apex:pageBlockSection>
<apex:pageBlockSection title="Section 2: Technical Contact (if applicable)" collapsible="false" columns="2" >
<apex:inputField value="{!Product_Brief__c.Technical_Contact__c}" rendered="{!bEditMode}"/>
<apex:outputField value="{!Product_Brief__c.Technical_Contact__c}" rendered="{!NOT(bEditMode)}" />
<apex:inputField value="{!Product_Brief__c.Title_Technical__c}" rendered="{!bEditMode}"/>
<apex:outputField value="{!Product_Brief__c.Title_Technical__c}" rendered="{!NOT(bEditMode)}" />
<apex:inputField value="{!Product_Brief__c.Phone_Technical__c}" rendered="{!bEditMode}"/>
<apex:outputField value="{!Product_Brief__c.Phone_Technical__c}" rendered="{!NOT(bEditMode)}" />
<apex:inputField value="{!Product_Brief__c.Email_Technical__c}" rendered="{!bEditMode}"/>
<apex:outputField value="{!Product_Brief__c.Email_Technical__c}" rendered="{!NOT(bEditMode)}" />
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton value="Previous Page" action="{!page2}"/>
<apex:commandButton action="{!doToggleEditMode}" value="Edit" reRender="myPanel" rendered="{!NOT(bEditMode)}" />
<apex:commandButton action="{!doSave}" value="Save" reRender="myPanel" rendered="{!bEditMode}" />
<apex:commandButton action="{!save}" value="SAVE"/>
<apex:commandButton value="PRINT" onclick="window.print();"/>
<apex:commandButton value="Cancel" action="{!Cancel}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
Extension
public class SUM {
public Product_Brief__c pb {get;set;}
public User u {get;set;}
private ApexPages.StandardController controller {get;set;}
public boolean bUpdate {get;set;}
public string loggedinUserId = UserInfo.getUserId();
public User u2 = [Select ContactId From User where Id =: '005R0000001Y6h4'];
public String ctId{
get {
// if (ctId==null){
// if (bUpdate){
ctId = u2.ContactId;
// }
return ctId;
// }
}
set;
}
Contact ct = [SELECT AccountId FROM Contact WHERE id=:ctId];
public string getacct(){
Account acct = [SELECT Name FROM Account WHERE id=:ct.AccountId];
return acct.Name;
return null;
}
Opportunity opp = [SELECT Id FROM Opportunity WHERE AccountId=:ct.AccountId LIMIT 1];
/* *************** Edit Sec. ************************ */
public Boolean bEditMode {
get {
if(bEditMode == null) {
bEditmode = false;
}
return bEditMode;
}
set;
}
public PageReference doToggleEditMode() {
bEditMode = !bEditMode;
return null;
}
public PageReference doSave() {
try {
// Do your stuff to save your record
controller.save();
doToggleEditMode();
}
catch(Exception ex) {
// Handle error
}
return null;
}
/* ********************************************** */
public PageReference page1(){
return Page.sumpage1;
}
public PageReference page2(){
return Page.sumpage2;
}
public PageReference page3(){
return Page.sumpage3;
}
public PageReference save() {
controller.save();
return null;
}
public SUM(ApexPages.StandardController controller) {
this.controller = controller;
}
}
When I click on the save button it will save, but my page will break. It suppose to redirect to the same page. But it does not. Anybody have any idea? Thanks
return null;
? That means you're explicitly asking to not redirect. You could tryreturn controller.save();
instead.if(controller.save() != null) { PageReference ref = Page.myPage; ref.setRedirect(true); return ref; } return null;
. Return no page reference if an error occurs, or a redirect otherwise.