0
<apex:page standardController="Opportunity" tabStyle="Opportunity">
<apex:form >
<apex:sectionHeader title="Opportunity Edit" subtitle="New Opportunity"/>
<apex:pageBlock title="Opportunity Details">
 <apex:pageBlockButtons >
   <apex:commandButton action="{!Save}" value="Save"/>
   <apex:commandButton action="{!Cancel}" value="Cancel"/>
 </apex:pageBlockButtons>  
</apex:pageBlock>
</apex:form>
</apex:page>

I want to add 'Save & New' action button on my vf page. I'm currently using 'Save' button, is it possible..?

  • are you takling about apex:CommanButton name only or you want New page also after save ? – Ankuli Dec 20 '16 at 13:00
  • I'm just considering <apex:commandButton> .. after saving record page will be redirected to same page – Atul Rakate Dec 20 '16 at 13:07
  • you can have value="Save & New" . if you are looking apart from rename, then please show your code. – Ankuli Dec 20 '16 at 13:08
  • <apex:page standardController="Opportunity" tabStyle="Opportunity"> <apex:form > <apex:sectionHeader title="Opportunity Edit" subtitle="New Opportunity"/> <apex:pageBlock title="Opportunity Details"> <apex:pageBlockButtons > <apex:commandButton action="{!Save}" value="Save"/> <apex:commandButton action="{!Cancel}" value="Cancel"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page> Code is something like this...I want to add one more button 'Save & new' – Atul Rakate Dec 20 '16 at 13:10
1

You need to write custom code for that. You can use and Save method to save record and after that redirect your user to same page.

Public pagereference saveNew()
{
  //Save the data here
  Pagereference pr = new Pagereference('/apex/YourCustomVFPage');
  pr.setRedirect(true);
  return pr;
}

and then you can call your method from VF page

<apex:commandButton value="Save and New" action="{!saveNew}" />
| improve this answer | |
  • @AtulRakate you need to use extension for that. You can use standardController.Save() here – Tushar Sharma Dec 20 '16 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.