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