1

I want to refresh an entire page after a record is saved using the save command button. I can't see why it is not refreshing as default. Here is the code of the page:

<apex:sectionHeader title="DBVC Maintenance Request Evaluation"/>
<apex:form >
<apex:pageBlock title="">
    <apex:pageBlockButtons >
        <apex:commandButton action="{!save}" value="Save"/>
        <apex:commandButton action="{!cancel}" value="Cancel"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection showHeader="true" title="Evaluate Maintenance Request" columns="1">

        <apex:inputField value="{!MR_Evaluation__c.Evaluation_Ref__c}"/>
        <apex:pageBlockSectionItem />
        <apex:inputField value="{!MR_Evaluation__c.Maintenance_Request_Ref__c}"/>
        <apex:pageBlockSectionItem />
        <apex:inputField value="{!MR_Evaluation__c.MR_Eval__c}"/>
        <apex:pageBlockSectionItem />
        <apex:inputField value="{!MR_Evaluation__c.Comments__c}"/>
        <apex:pageBlockSectionItem />
        <apex:inputField value="{!MR_Evaluation__c.Service_Provider__c}"/>
        <apex:pageBlockSectionItem />
    </apex:pageBlockSection>


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

4
  • use this <apex:commandButton action="{!save}" value="Save" rerender="" />
    – Amjad khan
    Dec 9 '16 at 11:07
  • I tried this too, it does not work. When the record is saved, it is attempting to take the guest user to the saved record, which they can not have access to. Dec 9 '16 at 11:21
  • Have you tried JS in oncomplete attribute of save button? Code like window.location.reload(true);. Dec 9 '16 at 13:14
  • No I haven't tried this, could you provide me with where exactly this would fit in my code above? Dec 9 '16 at 14:19
1

The standard controller do not provide this functionality out of the box so you would need to write an extension class for this -

VisualForce Page

<apex:commandButton action="{!SaveAndNew}" value="Save and New"/>

Define a method SaveAndNew on your controller extension

public PageReference SaveAndNew() {
   myStdController.save();        
   PageReference pr = new PageReference('/apex/{REPLACE_WITH_YOUR_VF_PAGE_NAME}');
   pr.setRedirect(true);
   return pr;
}

where myStdController is an instance variable of type ApexPages.StandardController and ensure to initialize it on the constructor of your controller extension class

3
  • So I need to create a new Apex Class using the code above in developer console? and once created it should allow me to save a record and stay on the page? Dec 9 '16 at 14:05
  • That's correct.. If you still any issue please provide both the VF page and the controller extension so that we can check
    – SF Rocks
    Dec 9 '16 at 14:26
  • VF page will need to reference the extension class via extensions="MyNewClass" attribute on the apex:page
    – cropredy
    Dec 10 '16 at 17:20
0

Use the Quick save action of standard controller to save your record.After save it will load into same page.Please see this example :

<apex:page standardController="Account">
  <apex:sectionHeader title="Account Quick Save"/>
<apex:form >
<apex:pageBlock title="">
    <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!quicksave}" id="saveButton"  />
        <apex:commandButton action="{!cancel}" value="Cancel"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection showHeader="true" title="Evaluate Maintenance Request" columns="1">

        <apex:inputField value="{!Account.Name}" />
        <apex:pageBlockSectionItem />
        <apex:inputField value="{!Account.Phone}"/>
        <apex:pageBlockSectionItem />

    </apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
</apex:page>
2
  • Thanks for your comment. Quick save works to save the record, but it still doesn't refresh the page to show blank fields, it remains on the page but doesn't give the user the impression that the record is saved. Dec 9 '16 at 12:19
  • I would like the page to reload with blank fields rather than retain the information, if this is possible. Dec 9 '16 at 12:20

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.