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
SabrentSabrent 

Save button on Visualforce page

 

I have here two VFP's one for Edit and one for Detail.

 

On Detail is a button called 'Edit' which opens the Edit page.

 

On the Edit page is a button called 'Save' and a button 'Cancel'. When i click the Save button, it saves the edited record  and navigates to the Detail page as defined in the save() method, however the Edit button on the Detail page is not displayed. Even the Cancel button navigates to where I was but the Edit button disappears from the Detail Page.

 

I thik there's some conflict between StandardController and the extension.

 

Can someone please takle a look and tell me what I doing wrong  .

 

Thanks.

 

 

Detail Page 

<apex:page standardController="Transaction__c" extensions="TransactionsCtrl" id="thePage" >
<apex:pagemessages />
<apex:form id="theForm" >  
     <apex:pageBlock id="detailsPB" title="Details" mode="detail">
          <apex:pageBlockButtons id="detailButtons" location="top" >
          <apex:commandButton id="editBtn" value="Edit" action="{!edit}" />    
          </apex:pageBlockButtons>
<apex:pageBlockSection title=" AUDIT RESEARCH" columns="2" id="pgBlckSct1">
    <apex:outputField id="rescodeFld" value="{!transaction.Research_Code__c}"/>
    <apex:outputField id="mancloseFld" value="{!transaction.Manually_Close_Y_N__c}"  />
</apex:pageBlockSection> 
</apex:pageBlock> 
</apex:form>
</apex:page>



Edit Page 

<apex:page standardController="Transaction__c" extensions="TransactionsCtrl" id="thePage" >
<apex:pagemessages />
<apex:form id="theForm" >  

<apex:pageBlock id="editPB" title="Edit" >
          <apex:pageBlockButtons id="editButtons" location="top" rendered="true">
          <apex:commandButton id="saveBtn" value="Save" action="{!save}" />
          <apex:commandButton id="cancelBtn" value="Cancel" action="{!cancel}" />
          </apex:pageBlockButtons>
<apex:pageBlockSection title="Audit Record" columns="2" id="pgBlckSct1">
<apex:inputField id="statusFld" value="{!transaction.Status__c}" />
<apex:inputField id="empidFld" value="{!transaction.EmplId__c}"  />
</apex:pageBlockSection> 

</apex:pageBlock> 
</apex:form>
</apex:page>


Class

public with sharing class TransactionsCtrl { 
    
    private ApexPages.StandardController stdController  { get; set; }
    public Transaction__c transaction { get; set; }
    
    public TransactionsCtrl(ApexPages.StandardController stdController) {
        
        
      System.debug('is it in the constructor');
      this.stdController = stdController;
      this.transaction = (Transaction__c)this.stdController.getRecord();

        pbatransaction = [SELECT Id, Name
                        FROM Transaction__c 
                                        WHERE Id = :transaction.Id limit 1];   
       }       
  public PageReference edit() {  
    PageReference page = new Pagereference('/apex/Transactions_Edit?Id='+transaction.Id);
        page.setRedirect(true);
        return page;
  }
        
  public PageReference save() {   
            try{
                update this.transaction;
                }catch(exception e){
                }
                PageReference page = new Pagereference('/apex/Transaction_Detail?Id='+transaction.Id);
            page.setRedirect(true);
            return page;
 }
 public Pagereference cancel(){
        PageReference newpage = new Pagereference('/apex/Transaction_Detail?Id='+transaction.Id);
        newpage.setRedirect(true);
        return newpage;
 }
   
}





 

Best Answer chosen by Admin (Salesforce Developers) 
Subramani_SFDCSubramani_SFDC

Y u are using standarrd controller..u simply use custom controller

 

refer this link

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_custom.htm

All Answers

Subramani_SFDCSubramani_SFDC

Y u are using standarrd controller..u simply use custom controller

 

refer this link

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_custom.htm

This was selected as the best answer
GlynAGlynA

There might be a conflict between your action methods and the same methods in the standard controller, which has save() and cancel() methods.  Your methods might not be getting called if the standard controller methods take priority.  Try renaming your action methods to something unique (e.g. saveAction(), cancelAction()) and see if you get different behavior.

 

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!

 

-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator

SabrentSabrent

Thanks Saurav and Glynn.

 

Documentation helped.

 

Soumyaranjan Pati 10Soumyaranjan Pati 10
hey rov you are using custom controller in place of standard controller plz change that .
Thanks
Soumyaranjan Pati