Overriding Save functionality

Overriding "Save" functionality when using a standard controller can be accomplished by a simple extension.

Visualforce page for inputing the data of the Testing__c object.

Custom Fields (Testing__c)
  • Name
  • City__c

Visualforce Page


<apex:page sidebar="false" standardController="Testing__c" extensions="OverrideSAVE">
  <apex:form >
      <apex:pageBlock >
          <apex:pageBlockSection columns="1">
              <apex:inputfield value="{!Testing__c.Name}"/>
              <apex:inputfield value="{!Testing__c.City__c}"/>
              <apex:commandButton value="SAVE" action="{!dosave}"/>
          </apex:pageBlockSection>
      </apex:pageBlock>
  </apex:form>
</apex:page>




  • Contructor fetching the inputfields data and storing the same in the "CON" variable. 
  • "doSave" method doing the saving of the inputted records and redirecting the page as required.

Apex Class



public with sharing class OverrideSAVE {

    ApexPages.StandardController con;
    public OverrideSAVE(ApexPages.StandardController controller) {
        con=controller;
    }
   
    public pagereference dosave(){
    con.save();
    pagereference ref=new pagereference('/apex/standardSavePage');
    ref.setredirect(true);
    return ref;
    }

}
We need your support,Please share/Like us on Facebook ⛅
Overriding Save functionality Overriding Save functionality Reviewed by dasfrogpractice on 06:24 Rating: 5

No comments:

Theme images by mariusFM77. Powered by Blogger.
Youtube Channel Image
Dasfrog Subscribe To watch more Salesforce Training
Subscribe