Auto Populate visualforce Page Fieldvalues

Requirement : We need to  add VisualForce Custom Save and Cancel button  on our visualForce Page.

To Add Visualforce Custom  Save and Cancel button copy the following code in you code.

Here is the Visualforce page

<apex:page>
  <apex:form>
    <apex:pageblock>
      <apex:pageBlockButtons>
      <apex:commandButton action="{!customSave}" value="Save"/>
      <button class="btn" style="padding:4px;" onclick="window.open('/{!$currentpage.parameters.id}', target='_self');return false;">Cancel</button>
    </apex:pageBlockButtons>
    </apex:pageblock>
  </apex:form>
</apex:page>

we need to write  customsave function on controller for save button action

Controller class: 

 

  public class yourController {
    
    public Account acc {get;set;}
   
  
    public ServiceExtController (ApexPages.StandardController stdController) 
    {
         this.acc = (Account)stdController.getRecord();
    }
    
    public PageReference customSave()
    {
        PageReference pr;
        try{
            database.upsert(acc);
            pr = new PageReference('/'+acc.Id );
        }catch( Exception e ){
            ApexPages.addMessages(e);
        }
        return pr;        
    }
   
}

 

Hits: 3480

Share Post

By Himanshu Rana

My Name is Himanshu Rana, 23 Years young, born and grow up in Ghaziabad, India. A High Spirited Salesforce Admin, Developer and a Blogger. I currently work at Wakencode Technologies,

Leave a Reply

Your email address will not be published. Required fields are marked *